Using javax.xml.parsers.DocumentBuilder class, an application programmer can obtain a org.w3c.dom.Document from XML.
This public org.w3c.dom.Document parse (InputStream is) has also other overloaded implementations for parsing a file; using the file name or the file objec(java.io.File)
Then you can retrieve the org.w3c.dom.Element by
org.w3c.dom.Element e = doc.getDocumentElement();
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
java.lang.Srting s = "<hello>Hello DOM Parser</hello>"; | |
java.io.InputStream sbis = new java.io.StringBufferInputStream(s); | |
javax.xml.parsers.DocumentBuilderFactory b = javax.xml.parsers.DocumentBuilderFactory.newInstance(); | |
b.setNamespaceAware(false); | |
org.w3c.dom.Document doc = null; | |
javax.xml.parsers.DocumentBuilder db = null; | |
db = b.newDocumentBuilder(); | |
doc = db.parse(sbis); |
This public org.w3c.dom.Document parse (InputStream is) has also other overloaded implementations for parsing a file; using the file name or the file objec(java.io.File)
Then you can retrieve the org.w3c.dom.Element by
org.w3c.dom.Element e = doc.getDocumentElement();