The string to document


public static Document string2doc(String xml) throws ParserConfigurationException, UnsupportedEncodingException, SAXException, IOException{
if (db == null) {
// first obtained: obtained  DOM  parser factory instance;
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
// then from  DOM  to get the factory  DOM  parser
db = dbf.newDocumentBuilder();
}
// The XML string into the input stream, through the DOM  into a parser DOM document.  
Document doc = db.parse(new java.io.ByteArrayInputStream(xml.getBytes("utf-8")));
doc.normalize();
return doc;
}

Guess you like

Origin blog.csdn.net/m0_37488170/article/details/72779290