Code Samples for PHP XML Parsers
The following three files show how you could write a php program to
produce a report for the cd2catalog.xml file that 1) prints each artist's
name in the format "lastname, firstname", and 2) prints the average price
paid for each artist's cds. The three files invoke PHP's expat, dom, and
simpleXML parsers:
- expat.html
- dom.html
- simple.html
The tyler script uses the PHP DOM parser to
create a new cd for Bonnie Tyler and add it to the cd2catalog file. It
also provides an example of using xpath to locate an element in the XML
tree and an example of how to modify the value of an element.