PHP XML Paser

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Renidrag
Forum Newbie
Posts: 4
Joined: Tue Feb 19, 2008 1:59 pm

PHP XML Paser

Post by Renidrag »

I am using the XML_Paser to parse Yahoo Search XML and it has been years since I worked with XML and these classes and functions in PHP are new to me, I can easily go throught and display the search listings that are contained in the attributes - BUT - I can not display the value of the text within the ClickURL element, I can only seen to get display element attributes with my function start($parser,$element,$attr)

Can someone show me how to display the text within the element, not the attributes, thanks
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: PHP XML Paser

Post by Christopher »

If you are using PHP5 you might want to look at Simple XML.
(#10850)
Renidrag
Forum Newbie
Posts: 4
Joined: Tue Feb 19, 2008 1:59 pm

Re: PHP XML Paser

Post by Renidrag »

Thanks for your reply,

I was looking into using Simple XML but the hosting service only uses php 4.3.9

Simple XML would make it so much easier, any other suggestions?

Thanks
Renidrag
Forum Newbie
Posts: 4
Joined: Tue Feb 19, 2008 1:59 pm

Re: PHP XML Paser

Post by Renidrag »

Update,

I found the solution, when using xml_parser() you set the xml_set_element_handler($this->parser,"start","stop"); which iterates through the xml feed, during this iteration the xml_set_character_data_handler($this->parser,"char"); is called and you use the function set above "char" to handle the data within the xml elements where as the "start" and "stop" functions handle the element attributes.

So basically the xml_parser is setup to do these steps, you have to set the name you want on the functions and you get to tell the functions what they will do - Documentation could be better thou and some examples of the flow of iteration etc.

but all in all my faith is restored :)
Post Reply