This Example shows you how to get the next Tag from the XML File. JAXP (Java API for XML Processing) is an interface which provides parsing of xml documents. Here the Document BuilderFactory is used to create new DOM parsers.There are some of the methods used in code given below for Modifying a DOM Tree:-
XMLInputFactory Factory = XMLInputFactory.newInstance():-By this method we create a new instance of the factory.
XMLStreamReader reader = Factory.createXMLStreamReader(new FileInputStream(file)):-Creates a new StreamReader which allows forward, read-only access to XML.
eventTypeID = reader.nextTag():-This method is used to skip events i.e COMMENT and PROCESSING_INSTRUCTION until a START_ELEMENT or END_ELEMENT is reached.
eventTypeID = reader.next():-By using this method we get the next parsing event.
Xml code for the program generated is:-
<?xml version="1.0" encoding="UTF-8"?>
|
NextTag.java
|
|
Output of the program:-
|
|
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: Getting next Tag in the XML File
Post your Comment