Java XML String Transform stringToNode(String s)

Here you can find the source of stringToNode(String s)

Description

string To Node

License

Open Source License

Declaration

public static Node stringToNode(String s) 

Method Source Code


//package com.java2s;
/*/*from w w w . j  a  va  2s . c  om*/
 * (c) 2005-2009 Carlos G?mez Rodr?guez, todos los derechos reservados / all rights reserved.
 * Licencia en license/bsd.txt / License in license/bsd.txt
 */

import java.io.StringReader;

import javax.xml.transform.Transformer;

import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;

import javax.xml.transform.dom.DOMResult;

import javax.xml.transform.stream.StreamSource;

import org.w3c.dom.Node;

public class Main {
    public static Node stringToNode(String s) {
        StreamSource ss = new StreamSource(new StringReader(s));
        DOMResult dr = new DOMResult();
        try {
            Transformer t = TransformerFactory.newInstance().newTransformer();
            t.transform(ss, dr);
        } catch (TransformerException te) {
            te.printStackTrace();
            return null;
        }
        return dr.getNode().getFirstChild();
    }
}

Related

  1. replaceLineSeparatorInternal(String string, String lineSeparator)
  2. save(Node doc, OutputStream stream, String encoding, boolean indent)
  3. signEmbeded(Node doc, String uri, PrivateKey pKey, X509Certificate cert)
  4. String2Doc(String InputXMLString)
  5. string2Source(String xml)
  6. strToSchema(final String strXsd)
  7. toElement(String xml)
  8. toHexString(byte[] array)
  9. toHTML(String xml)