Is there a cleaner way to achieve this: The XML is:
<Specifics>
<Name>
<Type>Brand</Type>
<Value>Apple</Value>
<Source>list</Source>
</Name>
<Name>
<Type>Country</Type>
<Value>USA</Value>
<Source>list</Source>
</Name>
<Name>
<Type>Rating</Type>
<Value>87</Value>
<Source>list</Source>
</Name>
<Name>
<Type>Project</Type>
<Value>Dolphin</Value>
<Source>list</Source>
</Name>
<Name>
<Type>Age</Type>
<Value>10-20</Value>
<Source>list</Source>
</Name>
</Specifics>
It works fine with the following just seems unwieldy. Is there a better way to get all the values for type
, value
and source
?
foreach($xml->Specifics as $specs) {
foreach($specs->Name as $name) {
foreach($name->children() as $child) {
echo $child->getName() . ": " . $child . "<br>";
}
}
}