Using Java API for XML parsing
Do you want to parse the XML documents using Java programming? Then you can use Java API for this purpose. By using the Java API you can write code that can manipulate the XML documents as you wish. It is easy to use this. You can download the Java API from the Sun Microsystems website.
Detailed documentation is also available for download from them. You can refer to the documentation for more details on the classes available and the methods available to manipulate XML document.
Importing proper packages and classes is necessary if you want to work with the Java API to handle the XML files. Your import statement would include the following,
Once you have imported these you can start creating a document object in three steps to load the XML document that you want to manipulate. A sample code to load the XML document in the document object is shown below:
db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Instead of creating the DocumentBuilder object in a single line of code as given above you can first create a DocumentBuilderFactory object and then from that you can create the DocumentBuilder.
The document has lots of methods to work with XML document. For example you might use the getElementsByTagName() method to get all the elements by a node name.
Amazon and the Amazon logo are trademarks of Amazon.com, Inc. or its affiliates.Copyright - © 2004 - 2019 - All Rights Reserved.