Web Hosting Talk







View Full Version : How obtain the three phones in this xml? Suggestions of parsers please


Corretja
07-09-2006, 01:03 PM
Hi,

Im learning the xml. I can parse (analize/read) all the xml without problems less when the xml has childrens with the same path and name. For example :





<Result>
<person:name>Alberto</person:name>
<person:detailinfo>
<person:address>alcala</person:address>
<person:city>madrid</person:city>
<person:phone>915658767</person:phone>
<person:phone>902345644</person:phone>
<person:phone>677234345</person:phone>
</person:detailinfo>
</Result>



I receive results in xml (as in the example) in a php variable ($xml_result) and i need show in screen the 3 phones of Albert. How can i do that with php?


Now im using the minixml parser (minixml.psychogenic.com) and works ok i can gather the <person:phone> but only the first match , i cant gather the rest. Can count the number of childers and if i know how is the xml result then with the position and one for get the others phone, but is a bad method because sometimes the number of results (childrens) of the xml resturned it varies (also the position)


How can i gather exactly the 3 phones? Please if somebody can put in php an example to me to do it... would be very appreciate. not necessarily with minixml parse, with any other parser of php or the default functions of php for xml (im not sure if it possible with them)


Many thanks and sorry for my bad english

submenu
07-29-2006, 05:02 PM
Are you using php 5 or 4? Php 5 has the SimpleXML module which allows you to turn any xml file into an object, so you can easily pull out any variable.

See: http://us2.php.net/manual/en/function.simplexml-load-file.php