Created
December 13, 2013 13:42
-
-
Save AmanTifli/7944375 to your computer and use it in GitHub Desktop.
Takes a string of xml and writes it to an xml file
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 void stringToDom(String xmlSource) | |
throws SAXException, ParserConfigurationException, IOException, TransformerException { | |
//parse the given input | |
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); | |
DocumentBuilder builder = factory.newDocumentBuilder(); | |
org.w3c.dom.Document doc = builder.parse(new InputSource(new StringReader(xmlSource))); | |
//write the document | |
TransformerFactory transformerFactory = TransformerFactory.newInstance(); | |
Transformer transformer = transformerFactory.newTransformer(); | |
DOMSource source = new DOMSource(doc); | |
StreamResult result = new StreamResult(new File("outFile.xml")); | |
transformer.transform(source, result); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment