无法从PHP解析XML

无法从PHP解析XML,php,xml,parsing,soap,Php,Xml,Parsing,Soap,我没能找到同样的问题,因此我决定开一家新公司。 我在下面遇到了一个问题。 目标是使用soap消息在UI上显示xml属性值。 PHP代码如下所示: $client = new SoapClient("https://domain.com/xml/listener.asmx?WSDL"); $results = $client->ProductDescription(array('Username' => "anyuser", 'Password' => "anypassword"

我没能找到同样的问题,因此我决定开一家新公司。 我在下面遇到了一个问题。 目标是使用soap消息在UI上显示xml属性值。 PHP代码如下所示:

$client = new SoapClient("https://domain.com/xml/listener.asmx?WSDL");
$results = $client->ProductDescription(array('Username' => "anyuser", 'Password' => "anypassword", 'code' => "1108324"));
print_r($results);
因此,我得到以下信息

stdClass Object ( [ProductDescriptionResult] => stdClass Object ( [any] => Imagehttp://catalog2.elkogroup.com/pictures/prDesc/large/1108324_425_0_425NULL.jpgDescription<h1 class="tagline"><span style="font-size: small">Quality surround audio for music, movies and games</span></h1> <p>&nbsp;Sound Blaster 5.1 VX is the absolute choice for those looking for better quality audio solutions basic motherboard audio can not deliver.</p>Vendor Homepagehttp://en.europe.creative.com/products/productarchive.asp?category=1&subcategory=873&product=17510&nav=Description2CREATIVE 5.1 VX (SB1071) OEMAudio-InInput/Output connectors1Audio-OutInput/Output connectors1MicrophoneInput/Output connectors1Included AccessoriesQuick start Guide; User Guide (on CD); Installation CDUnit Brutto Volumecubm0.001555Unit Net Weightkg0.13Unit Gross Weightkg0.157 ) )
调用未定义的方法stdClass::xpath()时出现错误消息

(c) 还尝试注册命名空间

$xml = simplexml_load_string($results);
$xml->registerXPathNamespace('envoy', 'https://ecom.elko.lv/xml');

但它告诉我simplexml_load_string()希望参数1是字符串

等等


您能帮我弄清楚吗?

从response元素(
ProductDescriptionResult
)获取它,这就是
SOAPClient
将提供给您的:

echo $results->ProductDescriptionResult->NewDataSet->Product[1]->Criteria;
请记住,这里不再有XML,
SOAPClient
已经为您将其转换为一个漂亮的对象树。可能在任何一点上都不存在上述跟踪(我只是根据XML猜测),在这种情况下,只需从
get\u object\u vars
执行
var\u dump
即可查看当前节点中的内容。哦,不要在浏览器中查看HTML输出,查看源代码,如果您将其视为HTML,调试输出中的大量
可能会“隐藏”内容


编辑:这在这里起作用

<?php
class S extends SoapClient {
        function __doRequest(){
                return  <<<XML
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body>
      <ProductDescriptionResponse xmlns="https://ecom.elko.lv/xml">
         <ProductDescriptionResult>
            <NewDataSet xmlns="">
               <Product>
                  <Criteria>Image1</Criteria>
                  <Value>http://test/1</Value>
               </Product>
               <Product>
                  <Criteria>Image2</Criteria>
                  <Value>http://test/2</Value>
               </Product>
            </NewDataSet>
        </ProductDescriptionResult>
      </ProductDescriptionResponse>
    </soap:Body>
</soap:Envelope>
XML;
        }
}
$d = new S(null,array('uri' => 'localhost','location' => 'localhost'));
$result = $d->somerequest();
echo $result->NewDataSet->Product[0]->Criteria;
'localhost','location'=>'localhost');
$result=$d->somerequest();
echo$result->NewDataSet->Product[0]->条件;

非常感谢您的快速响应。我尝试了您的建议,但我仍然无法读取Criteria参数的值。错误消息是未定义的属性:stdClass::$NewDataSet。我还按照您的建议检查了源代码,在那里我可以找到xml结构。我已经编辑好了,但是请。。。将
var\u dump
作为好友,它会告诉您变量是什么以及变量中包含什么。var\u dump返回以下结果。对象(stdClass)[44]公共“ProductDescriptionResult”=>对象(stdClass)[45]公共“任意”=>字符串”图像。。。(长度=5730)我想我明白为什么了。我尝试使用echo$results->ProductDescriptionResult->any;在这个例子中,我收到了这个字符串。我应该将这个字符串转换成XML,然后我就可以正确地读取它了…嗯,返回它将是一件奇怪的事情,除非使用的WSDL不是特别合适。。。上面的代码现在可以工作了吗,还是您仍然有问题?
$xml = simplexml_load_string($results);
$xml->registerXPathNamespace('envoy', 'https://ecom.elko.lv/xml');
echo $results->ProductDescriptionResult->NewDataSet->Product[1]->Criteria;
<?php
class S extends SoapClient {
        function __doRequest(){
                return  <<<XML
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body>
      <ProductDescriptionResponse xmlns="https://ecom.elko.lv/xml">
         <ProductDescriptionResult>
            <NewDataSet xmlns="">
               <Product>
                  <Criteria>Image1</Criteria>
                  <Value>http://test/1</Value>
               </Product>
               <Product>
                  <Criteria>Image2</Criteria>
                  <Value>http://test/2</Value>
               </Product>
            </NewDataSet>
        </ProductDescriptionResult>
      </ProductDescriptionResponse>
    </soap:Body>
</soap:Envelope>
XML;
        }
}
$d = new S(null,array('uri' => 'localhost','location' => 'localhost'));
$result = $d->somerequest();
echo $result->NewDataSet->Product[0]->Criteria;