Here you can find the source of stringToDOM(String xmlString)
Parameter | Description |
---|---|
xmlString | XML as string |
Parameter | Description |
---|---|
ParserConfigurationException | an exception |
SAXException | an exception |
IOException | an exception |
public static Element stringToDOM(String xmlString) throws ParserConfigurationException, SAXException, IOException
//package com.java2s; //License from project: Apache License import java.io.IOException; import java.io.Reader; import java.io.StringReader; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.xml.sax.InputSource; import org.xml.sax.SAXException; public class Main { /**/*from w w w . j a v a 2 s . com*/ * Transforms a string representation to a DOM representation * @param xmlString XML as string * @return DOM representation of String * @throws ParserConfigurationException * @throws SAXException * @throws IOException */ public static Element stringToDOM(String xmlString) throws ParserConfigurationException, SAXException, IOException { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); DocumentBuilder builder = dbf.newDocumentBuilder(); Reader reader = new StringReader(xmlString); InputSource src = new InputSource(reader); Document domDoc = builder.parse(src); return domDoc.getDocumentElement(); } }