Hello,
I have some xml data in the format below -
<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>
I do something like
$xml = simplexml_load_string($xml_data);
$namespaces = $xml->getNameSpaces(true);
$data = $xml->children($namespaces['xyz']);
so if I print
echo $data->totalRecords; //outputs correctly 659
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
$records = $data->records;
foreach($records as $record) {
echo print_r($record, true);
}
but it wasnt very helpful.
My questions are -
- how to access each <xyz:record>
and its sub items (which are <str name="abc">NAbc</str>
etc?
With thanks, Kay