Talk:Parsing XML using JSR 172

From Nokia Developer Wiki
Jump to: navigation, search
24 Sep
Article Review by Larry101 (20090924)

This article provides a fairly simple example of how to parse an XML file using JSR 172 (Web Service) API. The code example demonstrates how to read in an XML file via an HTTPConnection and parse this file using the web service API. The example demonstrates the use of the different classes within the API, without actually doing anything with the contents of the XML file (most of the methods for parsing the XML file are left blank).

In some respects, the simplicity of the code example could be criticised, because it doesn’t actually show how to do things like identify the current tag, retrieve an attribute or retrieve the contents of a tag containing text. However, other examples exist to show this functionality. This article is merely intended to show which objects to use to create a parser object and initiate the parsing process. Code to perform the actual parsing requires an illustrative example to be meaningful. The code example shows how a SAXParser object is created using the factory design pattern, with an instance being created using the newSAXParser() method of the SAXParserFactory class.

A useful follow up article would be to demonstrate how to use the methods such as startElement, endElement and characters to retrieve specific information from an XML file. These methods are generally used in conjunction with a stack data structure to process data in XML format.