Here you can find the source of parseXml(String xml)
Parameter | Description |
---|---|
xml | String that represents the XML data. |
public static Document parseXml(String xml)
//package com.java2s; import org.w3c.dom.Document; import org.xml.sax.InputSource; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import java.io.StringReader; public class Main { /**/* w w w .j a v a2 s . c o m*/ * Returns a new document for the given XML string. * * @param xml String that represents the XML data. * @return Returns a new XML document. */ public static Document parseXml(String xml) { try { DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory .newInstance(); DocumentBuilder docBuilder = docBuilderFactory .newDocumentBuilder(); return docBuilder.parse(new InputSource(new StringReader(xml))); } catch (Exception e) { e.printStackTrace(); } return null; } }