Create DomElement From XML String


import java.io.StringReader;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.*;
import org.xml.sax.InputSource;

public class DomParser{

 public static Element createDomElementFromXMLString(String xmlString)
    {
        InputSource inputSource;
        StringReader stringReader = new StringReader(xmlString);
        inputSource = new InputSource(stringReader);
        Document document;
        DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
        document = docBuilder.parse(inputSource);
        return document.getDocumentElement();
        JVM INSTR pop ;
        return null;
    }
}

No comments:

Post a Comment