Ik probeer te iterate over xml files met simplexml een voorbeeld xml file ziet er bv:
<?php
$rawXml = "<?xml version='1.0'?>
<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>
<xs:element name='A'>
<xs:complexType>
<xs:sequence>
<xs:element name='item'>
<xs:complexType>
<xs:sequence>
<xs:element name='1' type='xs:string'/>
<xs:element name='2' type='xs:string'/>
<xs:element name='3' type='xs:string'/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name='B'>
<xs:complexType>
<xs:sequence>
<xs:element name='1' type='xs:string'/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
^
zo uit |
Ik krijg <xs:element name='1' type='xs:string'/> helaas niet te pakken
$xml = new SimpleXMLElement($rawXml);
$namespaces = $xml->getNamespaces();
$namespace = $namespaces['xs'];
$children = $xml->children($namespace);
var_dump($children);
$element = $children[0];
if (isset($children[1])){
$element2 = $children[1];
$elementAttributes2 = $element2->attributes();
$elementName2 = $elementAttributes2['name'];
$elementName2 = $elementAttributes['name'];
echo $elementName2 .'<br />';
foreach ($element2->complexType->sequence->children($namespace) as $child){
echo 'NODE: ' . ($child->attributes()->name) .' TYPE: '. $child->attributes()->type . '<br />';
}
}
$elementAttributes = $element->attributes();
$elementName = $elementAttributes['name'];
echo $elementName .'<br />';
foreach ($element->complexType->sequence->children($namespace) as $child){
echo 'NODE: ' . ($child->attributes()->name) .' TYPE: '. $child->attributes()->type . '<br />';
}
<xs:complexType> <xs:sequence> <xs:element name="item"> <xs:complexType> <xs:sequence>
</xs:element> <xs:element name="commanditem"> <xs:complexType> <xs:sequence> <xs:element name="command" type="xs:string"/>
</xs:sequence>
</xs:complexType>