How to retrieve children of an xml data?

Avionixx

New Member
I have some xml data in the format below -\[code\]<xyz:reqResponse xmlns:xyz="http://www.test.com/xyz/" xmlns:akt="http://www.exmple.com/akt/"> <xyz:version>1.2</xyz:version> <xyz:totalRecords>659</xyz:totalRecords> <xyz:records> <xyz:record> <doc> <str name="icon_url">http://www.icons.net/icon1.jpg</str> <str name="type">Service</str> <arr name="bc.recordTitle"><str>Evergreen Club</str></arr> <str name="bc.id">KLM0078</str> <str name="system.external.id">787678</str> <arr name="bc.description"> <str>Meetings: Church Hall Beaudesert Lane. Open to anyone over 50.</str> </arr> <str name="code">X1209</str> <double name="localval1">-4.00006</double> <double name="localval2">-7.00012</double> <date name="timestamp">Wed Jun 02 21:19:33 BST 2010</date> </doc> </xyz:record> <xyz:record> <doc> <str name="icon_url">http://www.icons.net/icon1.jpg</str> <str name="type">Service</str> <arr name="bc.recordTitle"><str>Evergreen Club</str></arr> <str name="bc.id">KLM0078</str> <str name="system.external.id">787678</str> <arr name="bc.description"> <str>Meetings: Church Hall Beaudesert Lane. Open to anyone over 50.</str> </arr> <str name="code">X1209</str> <double name="localval1">-4.00006</double> <double name="localval2">-7.00012</double> <date name="timestamp">Wed Jun 02 21:19:33 BST 2010</date> </doc> </xyz:record> </xyz:records></xyz:reqResponse>\[/code\]I do something like \[code\]$xml = simplexml_load_string($xml_data); $namespaces = $xml->getNameSpaces(true);$data = http://stackoverflow.com/questions/3916924/$xml->children($namespaces['xyz']);\[/code\]so if I print\[code\]echo $data->totalRecords; //outputs correctly 659\[/code\]I am trying to loop through all of the records and access individual fields but have no clue how to do that.I tried something like\[code\]$records = $data->records;foreach($records as $record) { echo print_r($record, true);}\[/code\]but it wasnt very helpful.My questions are -- how to access each \[code\]<xyz:record>\[/code\] and its sub items (which are \[code\]<str name="abc">NAbc</str>\[/code\] etc?With thanks,Kay
 
Back
Top