In the existent world, XML documents are extremely structured and precisely defined. A great deal of effort goes into scheming XML information products. One reason for the amount of effort that is essential is the extensible nature of XML. XML gives you a set of rules that allows you to generate these complex structured documents.
Those rules, however, provide for an almost infinite amount of possibilities for defining a document's structure. Keep that in mind when creating a PHP XML parsing application. Each application that you create will only work with one particular document structure. The extra endeavor spent designing the document structure pays off when you code applications that will parse that data.
Having assumed that, this next example tackles a couple of problems you will find in coding parsers for your own XML documents. These troubles include multiple instances of the same component (usually differentiated by attributes or content) and attributes: two things you are sure to find in "real" XML documents. The complexity of the example document, bebop.xml, is fairly basic, but as you will see, the complexity of coding a PHP parser to read more complex documents doesn't necessarily increase; it is really just doing a lot more of the same thing over and over. The basic function of the element and character handlers does not change. You just need to add additional cases to encompass the additional variations that your document requires.
This next example shows how a more complex document can be parsed and how to present the resulting data. The XML file is the beginning of series synopsis for the popular anime title, Cowboy Bebop. Although it is far from complete as far as the series information goes, the XML structure allows for adding data to make the document more comprehensive.
The output appears as in the following Figure: