Java tutorial
//package com.java2s; /******************************************************************************* * Copyright (c) 2015 CA. All rights reserved. * * This source file is licensed under the terms of the Eclipse Public License 1.0 * For the full text of the EPL please see https://www.eclipse.org/legal/epl-v10.html *******************************************************************************/ import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.w3c.dom.Document; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import java.io.IOException; import java.io.StringReader; public class Main { /** * Converts the xml into a document * * @param xml the xml formated string * @return a new document * @throws SAXException * @throws IOException * @throws ParserConfigurationException */ public static Document xmlToDoc(String xml) throws SAXException, IOException, ParserConfigurationException { Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder() .parse(new InputSource(new StringReader(xml))); return doc; } }