2

Below is the XML that I am trying to convert using simplexml_load_string().

$THE_XML = '<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
  <ns:getMarketsByNpaNxxResponse xmlns:ns="http://ws.inventory.ccds.com" xmlns:ax251="http://exceptions.commons.ccds.com/xsd" xmlns:ax250="http://exceptions.ccds.com/xsd" xmlns:ax260="http://availability.item.productsservices.ccds.com/xsd" xmlns:ax259="http://detail.item.productsservices.ccds.com/xsd" xmlns:ax264="http://item.productsservices.ccds.com/xsd" xmlns:ax257="http://ws.inventory.ccds.com/xsd" xmlns:ax255="http://security.ccds.com/xsd"><ns:return xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ax257:Market">
    <ax257:marketId>30</ax257:marketId>
    <ax257:marketName>AZ-FLAGSTAFF</ax257:marketName> 
    <ax257:npaNxxs>928863</ax257:npaNxxs>
    </ns:return>
  </ns:getMarketsByNpaNxxResponse>
</soapenv:Body>
</soapenv:Envelope>';


$RESULT = simplexml_load_string($THE_XML);

var_dump($RESULT);

Returns:

object(SimpleXMLElement)#3 (0) {
}

What am I doing wrong?

7
  • That's not an empty object - SimpleXMLElement has its own implementation of var_dump() that doesn't usually show recursive nodes. It would be (bool)false if it failed to load. Commented Jan 20, 2014 at 18:54
  • Do you know how to retrieve the namespaced child nodes? Commented Jan 20, 2014 at 18:55
  • Can you show an example of how you would show the results of the returned XML object? Commented Jan 20, 2014 at 19:02
  • 1
    If you understand XML namespaces and how SimpleXML handles them, these should set you on your way. Some examples: stackoverflow.com/questions/6027398/…, stackoverflow.com/questions/6843025/simplexml-and-namespaces Important for you is to $RESULT->children('soapenv', true)->Body->children('ns', true)->getMarketsByNpaNxxResponse->children('ax257', true)->marketName Commented Jan 20, 2014 at 19:32
  • Thanks that example really helped - but this is so coarse to parse - it seems overly difficult :/ Commented Jan 20, 2014 at 19:42

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.