Code samples on parsing XML files in JavaParsing XML file using Java is easy if you are using the Java API for XML (JAXP) processing. You can download the JAXP from the Sun Microsystems website. You can also find the specifications of JAXP in the same website. A sample line of code that would parse the XML fine into a document object is given below. Document doc = dbuild.parse(new File("xmlfile.xml")); In the above line 'doc' is the document object that is used to load the XML document that you want to work with. 'dbuild' is the DocumentBuilder object. Before you create a 'doc' object you need to create a DocumentBuilderFactory and then a DocumentBuilder. Once the XML document is loaded into the document object, you can use the methods available to manipulate the elements of the XML document. For example to get all the elements of a particular tag name you would using the method getElementsByTagName() method of the document object. Similarly methods to change and remove elements and to create attributes are also available. You can find lots of code samples for XML processing the Sun Microsystems website.
|
|
||
|
|||
“Amazon and the Amazon logo are trademarks of Amazon.com, Inc. or its affiliates.”
Copyright - © 2004 - 2019 - All Rights Reserved.