Here you can find the source of loadDocument(String xmlString)
Parameter | Description |
---|---|
xmlString | the xml string |
Parameter | Description |
---|---|
Exception | the exception |
public static Document loadDocument(String xmlString) throws Exception
//package com.java2s; import java.io.StringReader; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Document; import org.xml.sax.InputSource; public class Main { /**/*from ww w .j a v a 2 s . c o m*/ * ***************************************** * Load XML document from string * ******************************************. * * @param xmlString the xml string * @return the document * @throws Exception the exception */ public static Document loadDocument(String xmlString) throws Exception { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setValidating(false); dbf.setNamespaceAware(true); DocumentBuilder db = dbf.newDocumentBuilder(); InputSource source = new InputSource(new StringReader(xmlString)); Document doc = db.parse(source); return doc; } }