Page 1 of 1

PHP XML Paser

Posted: Tue Feb 19, 2008 2:07 pm
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

Re: PHP XML Paser

Posted: Tue Feb 19, 2008 2:18 pm
by Christopher
If you are using PHP5 you might want to look at Simple XML.

Re: PHP XML Paser

Posted: Wed Feb 20, 2008 1:11 am
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

Re: PHP XML Paser

Posted: Wed Feb 20, 2008 10:04 am
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 :)