Parsing XML with PHP - not DOM XML

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I am not really sure how to parse files with PHP XML other than DOM
XML. Unfortunetely, I have run into a few problems with size and was
told that for the type of parsing I am doing I would be better using
event driven parsing like SAX.

Below I have a simple example of XML similar (although much much
smaller) to the one I am using for real.


  <name age="25">Martyn</name>
  <name age="24">Neil</name>
  <name age="24">Robbie</name>

All I want to do is to output them as:

Martyn (25)
Neil (24)
Robbie (24)

How would I do this uisng something like SAX / EXPAT? I found tutorials
but didnt really understand them enough to know if I was looking up the
correct thing. Any help would be much appreciated.



Re: Parsing XML with PHP - not DOM XML

The XML extension to php implements expat.

The manual has a very straight forward examples.

But if you want a wrapper: I like the xml classes found here /. For something simple like this
check out class_path_parser. There is an example there as well. It's
kinda old now so some of the functions may have depreciated.

But I suppose the pear xml package
( ) would be
more up to date.

Site Timeline