Last active
January 2, 2016 18:48
-
-
Save skytreader/8345791 to your computer and use it in GitHub Desktop.
Java util snippets
This file contains 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
/** | |
Parse an XML String. It may be worthwhile to cache the DocumentBuilder | |
object so we do not need to create an object everytime the method is | |
invoked. | |
@param xml | |
@return an org.w3c.dom.Document object | |
@referece http://stackoverflow.com/a/562207/777225 | |
*/ | |
public static Document loadXMLFromString(String xml) throws Exception | |
{ | |
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); | |
DocumentBuilder builder = factory.newDocumentBuilder(); | |
InputSource is = new InputSource(new StringReader(xml)); | |
return builder.parse(is); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment