I'm currently trying to create a generic PHP class to enable retrieval of XML data. The data all comes in a similar format but will have different element names and sometimes there may be more elements. Example xml:
One feed may show this:
<GroupData>
<Table diff:id="1">
<Code>1</Code>
<Name>Red</Name>
<Type>X</Type>
</Table>
<Table diff:id="2">
<Code>2</Code>
<Name>Yellow</Name>
<Type>Y</Type>
</Table>
</GroupData>
Another feed might show:
<GroupData>
<Table diff:id="1">
<Code>1</Code>
<Name>Red</Name>
</Table>
<Table diff:id="2">
<Code>2</Code>
<Name>Yellow</Name>
</Table>
</GroupData>
My PHP looks like this:
$dom = DOMDocument::loadXML($xml);
$node_list = $dom->getElementsByTagName('Table');
for($i=0; $i < $node_list->length; $i++) {
echo $node_list->item($i)->nodeValue;
}
This brings back data, but it's not quite what I'm looking for. I'd like it splitting out so I can see the element name and the element value and then create an array out of the data for future use. Is there a way of doing this without using "getElementsByTagName" which is what I have used before to get XML? I know each feed I receive will have Table so I can loop through this each time. Thanks for the help.