Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.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
PHP7文档XML xpath->;查询获取子节点值_Php_Xpath_Domdocument_Xpathquery - Fatal编程技术网

PHP7文档XML xpath->;查询获取子节点值

PHP7文档XML xpath->;查询获取子节点值,php,xpath,domdocument,xpathquery,Php,Xpath,Domdocument,Xpathquery,我正试图从以下内容中提取一些信息: 传递API_Name我想检索此类API所需的节点名称和一些其他信息 假设我们想要获得AddDisputeNod节点,AddDisputeNode作为第一个节点 <xs:element name="DisputeExplanation" type="ns:DisputeExplanationCodeType" minOccurs="0"> <xs:annotation> <xs:documentation&g

我正试图从以下内容中提取一些信息: 传递API_Name我想检索此类API所需的节点名称和一些其他信息 假设我们想要获得
AddDisputeNod
节点,
AddDisputeNod
e作为第一个节点

<xs:element name="DisputeExplanation" type="ns:DisputeExplanationCodeType" minOccurs="0">
    <xs:annotation>
        <xs:documentation>
            This enumerated ....
        </xs:documentation>
        <xs:appinfo>
            <CallInfo>
                <CallName>AddDispute</CallName>
                <RequiredInput>Yes</RequiredInput>
                <allValuesExcept>PaymentMethodNotSupported, ShipCountryNotSupported, Unspecified, UPIAssistance, UPIAssistanceDisabled</allValuesExcept>
            </CallInfo>
            <SeeLink>
                <Title>Creating and Managing Disputes With Trading API</Title>
                <URL>http://developer.ebay.com/DevZone/guides/features-guide/default.html#development/UPI-DisputesAPIManagement.html#UsingAddDispute</URL>
            </SeeLink>
        </xs:appinfo>
    </xs:annotation>
</xs:element>
虽然我没有得到任何结果:

我得到它的唯一方法是添加两个嵌套循环:

$RequiredInput = $xpath->query('xs:annotation/xs:appinfo',$node);//->item(0);
  foreach($RequiredInput->childNodes as $nn)
  {
    foreach($nn->childNodes as $nnn)
    {
      echo '<br />'.$nnn->nodeName.' => '.$nnn->nodeValue;
    }
  }
$requireInput=$xpath->query('xs:annotation/xs:appinfo',$node);//->项目(0);
foreach($requireInput->childNodes作为$nn)
{
foreach($nn->childNodes作为$nnn)
{
回显“
”。$nnn->nodeName.=>”。$nnn->nodeValue; } }
似乎不接受内部节点没有xs:namespace

但这对我来说似乎是胡说八道,但我找不到正确的解决办法。
是否可以建议我做的错误?

因为完整文档声明
xmlns=“urn:ebay:api:eblbaseconts”
非前缀元素,如
CallInfo
最终会出现在默认命名空间
urn:ebay:api:eblbaseconts
中,因此,与默认命名空间中的任何元素一样,要使用XPath1.0选择它们,需要使用前缀,例如

$xpath->registerNamespace('ebl', 'urn:ebay:apis:eBLBaseComponents');

$RequiredInput = $xpath->query('xs:annotation/xs:appinfo/ebl:CallInfo/ebl:RequiredInput',$node)

当您当前尝试使用例如
CallInfo
时,尝试在no命名空间中选择具有本地名称
CallInfo
的元素,而您需要在该特定命名空间中选择
CallInfo
元素。

您完全正确。

非常感谢!现在我可以处理递归了,不过我想我还需要进一步的帮助:-(
$RequiredInput = $xpath->query('xs:annotation/xs:appinfo',$node);//->item(0);
  foreach($RequiredInput->childNodes as $nn)
  {
    foreach($nn->childNodes as $nnn)
    {
      echo '<br />'.$nnn->nodeName.' => '.$nnn->nodeValue;
    }
  }
$xpath->registerNamespace('ebl', 'urn:ebay:apis:eBLBaseComponents');

$RequiredInput = $xpath->query('xs:annotation/xs:appinfo/ebl:CallInfo/ebl:RequiredInput',$node)