If you just want to put the contents of a string in a file, it really doesn't matter if it is actually XML or not. You can skip parsing (which is a relatively expensive operation) and just dump String to a file, for example:
public static void stringToDom(String xmlSource) throws IOException { java.io.FileWriter fw = new java.io.FileWriter("my-file.xml"); fw.write(xmlSource); fw.close(); }
If you want to be safe and get around encoding problems, as Joachim pointed out, you'll need a parsing. Since its good practice to never trust your source data, this may be the preferred way. It will look like this:
public static void stringToDom(String xmlSource) throws SAXException, ParserConfigurationException, IOException {
source share