tags:

views:

22

answers:

1

I have a SOAP Response which I want convert to a DOM Document. I am using loadxml() for that, but it returns an empty object.

<?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"&gt;&lt;S:Body&gt;&lt;ns2:getResponse xmlns:ns2="http://api.sponsoredlistings.ask.com/api/v5/"&gt;&lt;rval xmlns="http://api.sponsoredlistings.ask.com/api/v5/"&gt;&lt;ns2:totalNumEntries&gt;6&lt;/ns2:totalNumEntries&gt;&lt;ns2:entries&gt;&lt;ns2:id&gt;3000063&lt;/ns2:id&gt;&lt;ns2:name&gt;QA_Team_1&lt;/ns2:name&gt;&lt;ns2:status&gt;ACTIVE&lt;/ns2:status&gt;&lt;ns2:servingStatus&gt;Inactive&lt;/ns2:servingStatus&gt;&lt;ns2:startDate&gt;20100730&lt;/ns2:startDate&gt;&lt;ns2:endDate&gt;20991231&lt;/ns2:endDate&gt;&lt;ns2:budget&gt;&lt;ns2:period&gt;MONTHLY&lt;/ns2:period&gt;&lt;ns2:amount&gt;&lt;ns2:amount&gt;3333.3333&lt;/ns2:amount&gt;&lt;/ns2:amount&gt;&lt;ns2:deliveryMethod&gt;STANDARD&lt;/ns2:deliveryMethod&gt;&lt;/ns2:budget&gt;&lt;ns2:biddingStrategy xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns2:ManualCPC"/><ns2:adServingOptimizationStatus>OPTIMIZE</ns2:adServingOptimizationStatus><ns2:stats><ns2:network>ALL</ns2:network><ns2:statsType>Stats</ns2:statsType></ns2:stats><ns2:statusReason>FutureDT</ns2:statusReason></ns2:entries><ns2:entries><ns2:id>3000064</ns2:id><ns2:name>Sample Campaign for Itay</ns2:name><ns2:status>ACTIVE</ns2:status><ns2:servingStatus>Inactive</ns2:servingStatus><ns2:startDate>20100730</ns2:startDate><ns2:endDate>20991231</ns2:endDate><ns2:budget><ns2:period>MONTHLY</ns2:period><ns2:amount><ns2:amount>3333.3333</ns2:amount></ns2:amount><ns2:deliveryMethod>STANDARD</ns2:deliveryMethod></ns2:budget><ns2:biddingStrategy xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns2:ManualCPC"/><ns2:adServingOptimizationStatus>OPTIMIZE</ns2:adServingOptimizationStatus><ns2:stats><ns2:network>ALL</ns2:network><ns2:statsType>Stats</ns2:statsType></ns2:stats><ns2:statusReason>FutureDT</ns2:statusReason></ns2:entries><ns2:entries><ns2:id>3000065</ns2:id><ns2:name>Sample Campaign API Report Testing 1</ns2:name><ns2:status>ACTIVE</ns2:status><ns2:servingStatus>Inactive</ns2:servingStatus><ns2:startDate>20100802</ns2:startDate><ns2:endDate>20991231</ns2:endDate><ns2:budget><ns2:period>MONTHLY</ns2:period><ns2:amount><ns2:amount>3333.3333</ns2:amount></ns2:amount><ns2:deliveryMethod>STANDARD</ns2:deliveryMethod></ns2:budget><ns2:biddingStrategy xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns2:ManualCPC"/><ns2:adServingOptimizationStatus>OPTIMIZE</ns2:adServingOptimizationStatus><ns2:stats><ns2:network>ALL</ns2:network><ns2:statsType>Stats</ns2:statsType></ns2:stats><ns2:statusReason>FutureDT</ns2:statusReason></ns2:entries><ns2:entries><ns2:id>3000066</ns2:id><ns2:name>CampaignSridRevewSB</ns2:name><ns2:status>ACTIVE</ns2:status><ns2:servingStatus>Active</ns2:servingStatus><ns2:startDate>20100810</ns2:startDate><ns2:endDate>20991231</ns2:endDate><ns2:budget><ns2:period>DAILY</ns2:period><ns2:amount><ns2:amount>10000.0</ns2:amount></ns2:amount><ns2:deliveryMethod>STANDARD</ns2:deliveryMethod></ns2:budget><ns2:biddingStrategy xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns2:ManualCPC"/><ns2:adServingOptimizationStatus>OPTIMIZE</ns2:adServingOptimizationStatus><ns2:stats><ns2:network>ALL</ns2:network><ns2:statsType>Stats</ns2:statsType></ns2:stats></ns2:entries><ns2:entries><ns2:id>3000067</ns2:id><ns2:name>Campaign #3000067</ns2:name><ns2:status>ACTIVE</ns2:status><ns2:servingStatus>Active</ns2:servingStatus><ns2:startDate>20100811</ns2:startDate><ns2:endDate>20991231</ns2:endDate><ns2:budget><ns2:period>DAILY</ns2:period><ns2:amount><ns2:amount>10000.0</ns2:amount></ns2:amount><ns2:deliveryMethod>STANDARD</ns2:deliveryMethod></ns2:budget><ns2:biddingStrategy xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns2:ManualCPC"/><ns2:adServingOptimizationStatus>OPTIMIZE</ns2:adServingOptimizationStatus><ns2:stats><ns2:network>ALL</ns2:network><ns2:statsType>Stats</ns2:statsType></ns2:stats></ns2:entries><ns2:entries><ns2:id>3000068</ns2:id><ns2:name>Campaign #3000068</ns2:name><ns2:status>ACTIVE</ns2:status><ns2:servingStatus>Active</ns2:servingStatus><ns2:startDate>20100811</ns2:startDate><ns2:endDate>20991231</ns2:endDate><ns2:budget><ns2:period>DAILY</ns2:period><ns2:amount><ns2:amount>10000.0</ns2:amount></ns2:amount><ns2:deliveryMethod>STANDARD</ns2:deliveryMethod></ns2:budget><ns2:biddingStrategy xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns2:ManualCPC"/><ns2:adServingOptimizationStatus>OPTIMIZE</ns2:adServingOptimizationStatus><ns2:stats><ns2:network>ALL</ns2:network><ns2:statsType>Stats</ns2:statsType></ns2:stats></ns2:entries></rval></ns2:getResponse></S:Body></S:Envelope>  

what could be the reason?

A: 

What tells you that it's empty? DOMDocument::loadxml() will return false it there's an error, rather than an empty object.

Anyway, when I run this code ($doc is the mile-long single line of xml you posted):

$dom = new DOMDocument();
$dom->loadXML($doc);
$node_list = $dom->getElementsByTagName('totalNumEntries');
$node = $node_list->item(0);
echo $node->nodeValue;

The output is "6", as expected.

GZipp
thanks for your hint, I used a var_dump to print the content:and the result of this var_dump is:object(DOMDocument)#17 (0) {}
Christian Gnoth