Creating a Generic Data Extractor for XML Files

Your next program will perform the same type of data extraction as was done in Listing 2.2. However, this time you'll adapt your traversal to the number of nodes by first determining what the number is and then using a loop to step through the array. Furthermore, the names of the nodes will be extracted and used as the labels. The XML data file that you'll use as your source will be Listing 2.3.

The following code will read the data from an XML file. The first step is to determine the number of nodes in the list of data nodes. Once that's done, a loop is used to step through the array and extract both the name and the contents of the node. These two values are then inserted into tags and placed ...

Get Sams Teach Yourself XML in 24 Hours now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.