I'm receiving xml data from a api request that I'm finding difficult to parse. I've included and example of what the response data looks like vs how I need it to parse it. I've included the code I'm using to parse the XML. My question is it is not very user friendly to use $xml->xpath('//SOAP-ENV:Body/ns1:add_purchase_orderResponse/return/item/value/item/value') I would prefer to use $xml->xpath('//SOAP-ENV:Body/ns1:add_purchase_orderResponse/return/result/status/code')
I'm I doing something wrong, or I'm I just stuck with ugly code because I'm getting ugly XML.
<?php
$orderXML = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope 
    xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:ns1="http://qqp.mypresswise.com/r/wsdl-order.php" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    xmlns:ns2="http://xml.apache.org/xml-soap" 
    xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    <SOAP-ENV:Body>
        <ns1:add_purchase_orderResponse>
            <return xsi:type="ns2:Map">
                <item>
                    <key xsi:type="xsd:string">result</key>
                    <value xsi:type="ns2:Map">
    <item>
        <key xsi:type="xsd:string">status</key>
        <value xsi:type="ns2:Map">
            <item>
                <key xsi:type="xsd:string">code</key>
                <value xsi:type="xsd:int">0</value>
            </item>
            <item>
                <key xsi:type="xsd:string">text</key>
                <value xsi:type="xsd:string">ok</value>
            </item>
        </value>
    </item>
                        <item>
                            <key xsi:type="xsd:string">data</key>
                            <value xsi:type="ns2:Map">
                                <item>
                                    <key xsi:type="xsd:string">webID</key>
                                    <value xsi:type="xsd:string">ZTJmYTA0NmI4NmVk</value>
                                </item>
                                <item>
                                    <key xsi:type="xsd:string">orderID</key>
                                    <value xsi:type="xsd:string">44604</value>
                                </item>
                                <item>
                                    <key xsi:type="xsd:string">items</key>
                                    <value xsi:type="ns2:Map">
                                        <item>
                                            <key xsi:type="xsd:string">item</key>
                                            <value SOAP-ENC:arrayType="ns2:Map[1]" xsi:type="SOAP-ENC:Array">
                                                <item xsi:type="ns2:Map">
                                                    <item>
                                                        <key xsi:type="xsd:string">itemID</key>
                                                        <value xsi:type="xsd:int">107263</value>
                                                    </item>
                                                    <item>
                                                        <key xsi:type="xsd:string">itemprice</key>
                                                        <value xsi:type="xsd:string">42</value>
                                                    </item>
                                                </item>
                                            </value>
                                        </item>
                                    </value>
                                </item>
                            </value>
                        </item>
                    </value>
                </item>
            </return>
        </ns1:add_purchase_orderResponse>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
XML;
$xml = simplexml_load_string($orderXML);
foreach($xml->xpath('//SOAP-ENV:Body/ns1:add_purchase_orderResponse/return/item/value/item/value') as $xmlItem) {
   /*if ($xmlItem->item[0]->key == "code"){
       echo "value=>" . $xmlItem->item[0]->value;
   } */
    if ($xmlItem->item[1]->key == "orderID"){
        echo "value=>" . $xmlItem->item[1]->value;
    }   
}
?>
