Created
September 3, 2012 08:43
-
-
Save sfalquier/3607940 to your computer and use it in GitHub Desktop.
load W3C xml Document object from a String
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static org.w3c.dom.Document loadXMLFromString(String xml) | |
throws org.xml.sax.SAXException, java.io.IOException { | |
return loadXMLFrom(new java.io.ByteArrayInputStream(xml.getBytes())); | |
} | |
public static org.w3c.dom.Document loadXMLFrom(java.io.InputStream is) | |
throws org.xml.sax.SAXException, java.io.IOException { | |
javax.xml.parsers.DocumentBuilderFactory factory = javax.xml.parsers.DocumentBuilderFactory | |
.newInstance(); | |
factory.setNamespaceAware(true); | |
javax.xml.parsers.DocumentBuilder builder = null; | |
try { | |
builder = factory.newDocumentBuilder(); | |
} catch (javax.xml.parsers.ParserConfigurationException ex) { | |
} | |
org.w3c.dom.Document doc = builder.parse(is); | |
is.close(); | |
return doc; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment