I want to create a Java program that will read an XML file and extract the information I specify. My question is, what is the best method to read nodes and extract information out of an XML document whose type is not known beforehand?

Serge Knystautas

SAX is very simple API to handle extracting information from an XML file. You register your class to the SAX parser as a listener of "SAX events", which are just when the parser hits certain different parts of the file. You will get calls when a tag is started, when a tag stops, and the character data within the tag. In each of these situations, the event will contain information about what tag was started or stopped and any attributes of that tag.

Try downloading the XercesJ parser from http://xml.apache.org/ and trying some of the SAX examples.

0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact