PHP Object-Oriented Solutions
Chapter 6
This chaper covers the beginning concepts and uses of SimpleXML.
Exericses
- Accessing Unknown Nodes
- The page displays the data in an XML file by accessing it with multiple
foreach
loops. The first two nodes ("node name" and "attribute") are accessed directly while the following nodes are displayed by looping through the remaining node's children without calling them by name. - Displaying Book Details
- The page displays the information in a web-friendly format. I altered the code which displays multiple authors to use commas for each, instead of an ampersand (&) for the final author.
- Outputting and Saving
SimpleXMLElement
Objects - The exercise is supposed to output the second object in the file to a new file and save it under a new name. Because of server permissions, the file will not work online.
- Displaying a News Feed
- On a server where write permissions are enabled, the script saves a news feed into a local XML file and then displays the content in a more human-friendly format.
- Registering Namespaces to Work with XPath
- The page displays various ways to access data through namespaces and XPath.