Here you can find the source of getDomElement(String aXml)
Parameter | Description |
---|---|
aXml | XML string |
public static Document getDomElement(String aXml)
//package com.java2s; import java.io.IOException; import java.io.StringReader; import javax.xml.parsers.DocumentBuilder; 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; public class Main { /**/*from www. jav a2 s. c o m*/ * Gets DOM structure * * @param aXml * XML string * @return DOM structure */ public static Document getDomElement(String aXml) { Document doc = null; DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); try { DocumentBuilder db = dbf.newDocumentBuilder(); InputSource is = new InputSource(); is.setCharacterStream(new StringReader(aXml)); doc = db.parse(is); } catch (ParserConfigurationException e) { return null; } catch (SAXException e) { return null; } catch (IOException e) { return null; } // return DOM return doc; } }