Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP Xpath为节点提取值_Php_Xml_Xpath_Domdocument - Fatal编程技术网

PHP Xpath为节点提取值

PHP Xpath为节点提取值,php,xml,xpath,domdocument,Php,Xml,Xpath,Domdocument,XML代码: <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> <s:Header> <a:Ac

XML代码:

 <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
  <s:Header>
      <a:Action s:mustUnderstand="1">http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher/fault</a:Action>
      <a:RelatesTo>urn:uuid:9C35A55C-A5B4-AC89-AF95-B287E727332E</a:RelatesTo>
      <ActivityId CorrelationId="427735e4-59b8-4176-a2b7-49f91b965d11" xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics">00000000-0000-0000-0000-000000000000</ActivityId>
      <o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
          <u:Timestamp u:Id="_0">
              <u:Created>2017-05-08T07:34:29.504Z</u:Created>
              <u:Expires>2017-05-08T07:39:29.504Z</u:Expires>
          </u:Timestamp>
      </o:Security>
  </s:Header>
  <s:Body>
      <s:Fault>
          <s:Code>
              <s:Value>s:Sender</s:Value>
              <s:Subcode>
                  <s:Value xmlns:a="http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher">a:DeserializationFailed</s:Value>
              </s:Subcode>
          </s:Code>
          <s:Reason>
              <s:Text xml:lang="en-US">The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://schemas.microsoft.com/xrm/2011/Contracts/Services:entity. The InnerException message was 'There was an error deserializing the object of type Microsoft.Xrm.Sdk.Entity. The value 'mehul' cannot be parsed as the type 'Boolean'.'.  Please see InnerException for more details.</s:Text>
          </s:Reason>
      </s:Fault>
  </s:Body>

这里如何使用DOMXPath查询PHP属性值

这里我们使用
DOMDocument
来检索输出

loadXML($string);
foreach($domDocument->getelementsbytagnames(“http://www.w3.org/2003/05/soap-envelope“,”值“)作为$Value)
{
echo$value->textContent;
echo PHP_EOL;
}
输出:

s:Sender

答:反序列化失败

非常感谢您的宝贵回复
   $dom = new \DOMDocument();
    $dom->loadXML($crmResponse);
    $domxpath = new \DOMXPath($dom);
    $domxpath->registerNamespace('u',"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");
    $domxpath->registerNamespace('a',"http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher");

    //$nodeList = $domxpath->query("//*[local-name()='RetrieveResult']/b:Attributes/b:KeyValuePairOfstringanyType[c:key='new_currentapplicationstatus']/c:value/b:Value/text()");
    $nodeList = $domxpath->query("//*[local-name()='RetrieveResult']/o:Security[u:Id='_0']");
    $nodeErr = $domxpath->query("//*[local-name()='RetrieveResult']/s:Fault/s:Value/text()");

    var_dump($nodeErr);exit;
<?php
ini_set('display_errors', 1);
$string=' <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
  <s:Header>
      <a:Action s:mustUnderstand="1">http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher/fault</a:Action>
      <a:RelatesTo>urn:uuid:9C35A55C-A5B4-AC89-AF95-B287E727332E</a:RelatesTo>
      <ActivityId CorrelationId="427735e4-59b8-4176-a2b7-49f91b965d11" xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics">00000000-0000-0000-0000-000000000000</ActivityId>
      <o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
          <u:Timestamp u:Id="_0">
              <u:Created>2017-05-08T07:34:29.504Z</u:Created>
              <u:Expires>2017-05-08T07:39:29.504Z</u:Expires>
          </u:Timestamp>
      </o:Security>
  </s:Header>
  <s:Body>
      <s:Fault>
          <s:Code>
              <s:Value>s:Sender</s:Value>
              <s:Subcode>
                  <s:Value xmlns:a="http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher">a:DeserializationFailed</s:Value>
              </s:Subcode>
          </s:Code>
          <s:Reason>
              <s:Text xml:lang="en-US">The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://schemas.microsoft.com/xrm/2011/Contracts/Services:entity. The InnerException message was \'There was an error deserializing the object of type Microsoft.Xrm.Sdk.Entity. The value \'mehul\' cannot be parsed as the type \'Boolean\'.\'.  Please see InnerException for more details.</s:Text>
          </s:Reason>
      </s:Fault>
  </s:Body>
  </s:Envelope>';
$domDocument= new DOMDocument();
$domDocument->loadXML($string);
foreach($domDocument->getElementsByTagNameNS("http://www.w3.org/2003/05/soap-envelope", "Value") as $value)
{
    echo $value->textContent;
    echo PHP_EOL;
}