Example of using Java for XML parsingParsing of an XML document can be easily done using Java when you load the XML document in the document object. So you have to create a document object and then load that object with the XML document that you want to parse. To work with the document object you have to include certain classes in your program and this is achieved by importing some packages as given below. import org.w3c.dom.Document; The next three lines of code would give you an idea on how to create the document object using Java. DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); Upon interpreting the above code you can find that an DocumentBuilderFactory object is created first and from that a DocumentBuilder is created. The DocumentBuilder is used to parse the XML file and load the XML file into the document object. Once you have the XML file loaded in the document object, you can easily work with the XML file according to your needs. There are methods like, getDocumentElement().getNodeName(),getElementsByTagName() that can be used to work with the XML document.
|
|
|||
|
||||
“Amazon and the Amazon logo are trademarks of Amazon.com, Inc. or its affiliates.”
Copyright - © 2004 - 2019 - All Rights Reserved.