Parsing XML with PHP - not DOM XML

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bizt

    Parsing XML with PHP - not DOM XML

    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.

    XML:

    <?xml...
    <root>
    <name age="25">Martyn </name>
    <name age="24">Neil</name>
    <name age="24">Robbie </name>
    </root>

    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.

    Cheers

    Burnsy

  • Sean

    #2
    Re: Parsing XML with PHP - not DOM XML

    The XML extension to php implements expat.

    The manual has a very straight forward examples. http://ie2.php.net/xml

    But if you want a wrapper: I like the xml classes found here
    http://phpxmlclasses.sourceforge.net/. For something simple like this
    check out class_path_pars er. 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
    (http://pear.php.net/manual/en/packag...xml-parser.php) would be
    more up to date.

    Comment

    Working...