Home arrow XML arrow Using PHP with XML (part 2)

Using PHP with XML (part 2)

PHP offers two methods of parsing an XML document. You've already seen how SAX works; in this article, find out how to use PHP's DOM functions to traverse an XML tree, and also learn about important differences between the two approaches.

  1. Using PHP with XML (part 2)
  2. Meet Joe Cool
  3. Building A Library
  4. Anyone For Chicken?
  5. Conclusions...
  6. ...And Links
By: icarus, (c) Melonfire
Rating: starstarstarstarstar / 3
June 20, 2001

print this article


In the first part of this article, I said that there were two approaches to parsing an XML document. SAX is one; the other uses the DOM to build a tree representation of the XML data structures in the document, and then offers built-in methods to navigate through this tree. Once a particular node has been reached, built-in properties can be used to obtain the value of the node, and use it within the script.

PHP4 comes with support for this "DOM parser" as well, although you may need to recompile your PHP binary with the "--with-dom" parameter to activate it. Windows users get a free ride, since a compiled binary is included with their distribution; however, they will still need to activate the extension in the "php.ini" configuration file.

Over the next few pages, I'm going to take a look at PHP's DOM functions, illustrating an alternative method of parsing XML data. I'll also attempt to duplicate the previous examples, marking up books and recipes with HTML tags, in order to demonstrate how either technique can be used to achieve the same result. Finally, I'll briefly discuss the pros and cons of the SAX and DOM approaches, and point you to some links for your further education.

Let's get started, shall we?

>>> More XML Articles          >>> More By icarus, (c) Melonfire

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Google Docs and Xpath Data Functions
- Flex Array Collection Sort and Filtering
- The Flex Tree Control
- Flex List Controls
- Working with Flex and Datagrids
- How to Set Up Podcasting and Vodcasting
- Creating an RSS Reader Application
- Building an RSS File
- An Introduction to XUL Part 6
- An Introduction to XUL Part 5
- An Introduction to XUL Part 4
- An Introduction to XUL Part 3
- An Introduction to XUL Part 2
- An Introduction to XUL Part 1
- XML Matters: Practical XML Data Design and M...

Developer Shed Affiliates


Dev Shed Tutorial Topics: