DOM XML在loadXML上丢失数据


DOM XML losing data on loadXML

我需要PHP DOM XML方面的帮助。

我有这个代码:

$xmlresponse= file_get_contents("https://webservices.cebroker.com/cebrokerwebservice.asmx/UploadXMLString?InXML=$data");
print_r ($xmlresponse);
echo "<br /> <br />";
$xmlFile = new DOMDocument();
$works = $xmlFile->loadXML($xmlresponse);
echo "working = " . $works;
$searchNode = $xmlFile->getElementsByTagName( "licensee" );
print_r ($xmlFile);

这是回应。第一个XML是来自web服务的响应。第二个XML文件是我尝试将第一个XML响应加载到新的XML对象中后得到的文件。

<licensees>
   <licensee valid="true" State="FL" licensee_profession="RN" licensee_number="2676612" state_license_format="" first_name="HENRY" last_name="GEITER" ErrorCode="" Message="" TimeStamp="11/16/2013 8:59:16 PM" />
   <licensee valid="true" State="FL" licensee_profession="PN" licensee_number="1063421" state_license_format="" first_name="HENRY" last_name="GEITER" ErrorCode="" Message="" TimeStamp="11/16/2013 8:59:16 PM" />
</licensees>
working = 1
DOMDocument Object ( [doctype] => [implementation] => (object value omitted) [documentElement] => (object value omitted) [actualEncoding] => utf-8 [encoding] => utf-8 [xmlEncoding] => utf-8 [standalone] => 1 [xmlStandalone] => 1 [version] => 1.0 [xmlVersion] => 1.0 [strictErrorChecking] => 1 [documentURI] => /home/content/14/6722114/html/CCRN411/inc/ [config] => [formatOutput] => [validateOnParse] => [resolveExternals] => [preserveWhiteSpace] => 1 [recover] => [substituteEntities] => [nodeName] => #document [nodeValue] => [nodeType] => 9 [parentNode] => [childNodes] => (object value omitted) [firstChild] => (object value omitted) [lastChild] => (object value omitted) [previousSibling] => [attributes] => [ownerDocument] => [namespaceURI] => [prefix] => [localName] => [baseURI] => /home/content/14/6722114/html/CCRN411/inc/ [textContent] => ) 

为什么当我试图加载XML以进行解析时,我的数据会消失?

我已经解决了这个问题。不确定这是最好的解决方案还是只是破解,但我得到了API的响应,并对其应用了html_decode_entities,并重新生成了xmlns名称空间信息。然后我把它写进了一个文件。我创建了一个新的DOM文档,并立即从保存的xml文件中重新加载它。然后一切都成功了。如果这是一个黑客,有一个更干净的方法来完成任务,请有人发布它并让我知道。

尝试使用getElementsByTagNameNS,因为元素是按名称命名的:

<?php
$xml = <<<END
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://example.com/CEBrokerWebService/">
    <licensees>
       <licensee valid="true" State="FL" licensee_profession="RN" licensee_number="2676612" state_license_format="" first_name="HENRY" last_name="GEITER" ErrorCode="" Message="" TimeStamp="11/16/2013 8:59:16 PM" />
       <licensee valid="true" State="FL" licensee_profession="PN" licensee_number="1063421" state_license_format="" first_name="HENRY" last_name="GEITER" ErrorCode="" Message="" TimeStamp="11/16/2013 8:59:16 PM" />
    </licensees>
</string>
END;

$doc = new DOMDocument();
$doc->loadXML($xml);
$nodes = $doc->getElementsByTagNameNS('http://example.com/CEBrokerWebService/', 'licensee');
printf("Found %d nodes'n", $nodes->length);
print $doc->saveXML();