$xml = simplexml_load_file('Request.xml');
$xml->registerXPathNamespace("ess", "localhost/ESS");
$partnums = array();
$xp = "descendant::ess:ProPartList/ess:ProPart/ess:SelectedPart";
$selected = $xml->xpath($xp);
$x = 0;
foreach($selected as $part) {
$partnuminfo = $part->xpath("//ess:PartNumInfo");
foreach($partnuminfo as $p) {
echo $p->asXML();
$_Type = (string)$part->children("ess",true)->PartNumType;
$partnums[$x] = array($_Type => (string)$part->children("ess",true)->PartNum);
$x++;
}
}
print_r($partnums);
Using the code above, I cannot seem to get my head around parsing the XML below:
<ess:ProInfo>
<ess:ProPartList>
<ess:ProPart>
<ess:SelectedPart>
<ess:PartNumInfo>
<ess:PartNumType>OE</ess:PartNumType>
<ess:PartNum>04715SNAA90ZZ</ess:PartNum>
</ess:PartNumInfo>
<ess:PartNumInfo>
<ess:PartNumType>IC</ess:PartNumType>
<ess:PartNum>536-01037</ess:PartNum>
</ess:PartNumInfo>
<ess:PartNumInfo>
<ess:PartNumType>PType</ess:PartNumType>
<ess:PartNum>536</ess:PartNum>
</ess:PartNumInfo>
</ess:SelectedPart>
</ess:ProPart>
<ess:ProPart>
<ess:SelectedPart>
<ess:PartNumInfo>
<ess:PartNumType>OE</ess:PartNumType>
<ess:PartNum>71570SNAA00</ess:PartNum>
</ess:PartNumInfo>
<ess:PartNumInfo>
<ess:PartNumType>IC</ess:PartNumType>
<ess:PartNum>536-01036</ess:PartNum>
</ess:PartNumInfo>
</ess:SelectedPart>
</ess:ProPart>
<ess:ProPart>
<ess:SelectedPart>
<ess:PartNumInfo>
<ess:PartNumType>OE</ess:PartNumType>
<ess:PartNum>66100SNEA00ZZ</ess:PartNum>
</ess:PartNumInfo>
<ess:PartNumInfo>
<ess:PartNumType>IC</ess:PartNumType>
<ess:PartNum>117-50338</ess:PartNum>
</ess:PartNumInfo>
</ess:SelectedPart>
</ess:ProPart>
<ess:ProPart>
<ess:SelectedPart>
<ess:PartNumInfo>
<ess:PartNumType>OE</ess:PartNumType>
<ess:PartNum>04655SNE305ZZ</ess:PartNum>
</ess:PartNumInfo>
</ess:SelectedPart>
</ess:ProPart>
</ess:ProPartList>
</ess:ProInfo>
And creating this array()
array(
0 => array("OE" => "04715SNAA90ZZ", "IC" => "536-01037", "PType" => "536"),
1 => array("OE" => "71570SNAA00", "IC" => "536-01036"),
2 => array("OE" => "66100SNEA00ZZ", "IC" => "117-50338"),
3 => array("OE" => "04655SNE305ZZ")
)