Once we have loaded some XML into the parser we can use the parser document
attribute to interrogate the data. Before we rush into this, let's take a closer look at
the XML we used in the previous example. The XML has been used to record the
contents of a music catalogue, in this case 'Some Music Collection'.
The root node is catalogue and has one attribute, name, which is used to identify the
catalogue in question. Next, there is an album node. This node encapsulates four other
nodes: name, artist, year, and tracks. The tracks node identifies individual tracks
in track nodes that identifies a name and the length of the track in a length attribute.
The parser document attribute is a JSimpleXMLElement object. JSimpleXMLElement
objects are used to describe individual XML nodes. In the case of the document
attribute, this is always the root node.
Having loaded the XML, we'll start interrogating the data by retrieving the name of
the catalogue:
$document =& $parser->document;
$catalogue = $document->attributes('name');
Notice that the first thing we do is get a reference to the document attribute.
Pages:
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382