Created
December 28, 2015 15:20
-
-
Save packmad/fbe39ddd44b1c4b4f31d to your computer and use it in GitHub Desktop.
transform a String into an org.w3c.dom.Document
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
import org.w3c.dom.Document; | |
import javax.xml.parsers.DocumentBuilder; | |
import javax.xml.parsers.DocumentBuilderFactory; | |
import org.xml.sax.InputSource; | |
public static Document loadXMLFromString(String xml) { | |
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); | |
try { | |
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); | |
InputSource inputSource = new InputSource(new StringReader(xml)); | |
return documentBuilder.parse(inputSource); | |
} catch (ParserConfigurationException|SAXException|IOException e) { | |
e.printStackTrace(); | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment