<info>
<form tableid="1">
<town_id>
<option value="5102">Moscow</option>
<option value="2587">London</option>
<option value="717">Madrid</option>
<option value="2513">Paris</option>
<option value="5071">Berlin</option>
</town_id>
</form>
</info>
I have such xml and wanna parse it throught simplexml_load_string. Function returns such object:
SimpleXMLElement Object
(
[form] => SimpleXMLElement Object
(
[@attributes] => Array
(
[tableid] => 1
)
[town_id] => SimpleXMLElement Object
(
[option] => Array
(
[0] => Moscow
[1] => London
[2] => Madrid
[3] => Paris
[4] => Berlin
)
)
)
)
I don't have second attributes value from town options. How can I get them? my code:
/** @var SimpleXMLElement $xml */
$xml = simplexml_load_string($data);
if (! is_object($xml)) return FALSE;
print_r($xml);
foreach($xml as $record){
$attr = $record->attributes();
$table_id = (int)$attr['tableid'];
foreach($record as $key => $value){
//$table_data[$table_id][$key][] = $value['option'];
print_r($value->attributes());
print_r($value['option']->attributes());
}
}
$value is a SimpleXMLElement object, but $value->attributes() and $value['option]->attributes() return empty array.