【发布时间】:2019-01-02 17:07:57
【问题描述】:
我有以下xml
<ReviseInventoryStatusResponse xmlns="urn:ebay:apis:eBLBaseComponents">
<Timestamp>2019-01-02T15:42:31.495Z</Timestamp>
<Ack>Warning</Ack>
<Errors>
<ShortMessage>Requested StartPrice and Quantity revision is redundant.</ShortMessage>
<LongMessage>The existing price and quantity values are identical to those specified in the request and, therefore, have not been modified.</LongMessage>
<ErrorCode>21917091</ErrorCode>
<SeverityCode>Warning</SeverityCode>
<ErrorParameters ParamID="ItemID">
<Value>770386906435</Value>
</ErrorParameters>
<ErrorParameters ParamID="SKU">
<Value/>
</ErrorParameters>
<ErrorClassification>RequestError</ErrorClassification>
</Errors>
<Errors>
<ShortMessage>Requested StartPrice and Quantity revision is redundant.</ShortMessage>
<LongMessage>The existing price and quantity values are identical to those specified in the request and, therefore, have not been modified.</LongMessage>
<ErrorCode>21917091</ErrorCode>
<SeverityCode>Warning</SeverityCode>
<ErrorParameters ParamID="ItemID">
<Value>770386906436</Value>
</ErrorParameters>
<ErrorParameters ParamID="SKU">
<Value/>
</ErrorParameters>
<ErrorClassification>RequestError</ErrorClassification>
</Errors>
...
</ReviseInventoryStatusResponse>
我需要获取在 ErrorParameters/Value 中 ParamID="ItemID" 中找到的给定 ItemID 的 ShortMessage
我已经能够检查是否存在具有给定值的节点:
$xmlr = new DOMDocument();
$xmlr->load('ReviseInventoryStatusResponse_error.xml');
$xpath = new DOMXPath($xmlr);
$xpath->registerNamespace('e', 'urn:ebay:apis:eBLBaseComponents');
$nodeExists=($xpath->query('//e:ErrorParameters[@ParamID="ItemID"]/e:Value[. = "770386906435"]')->length>0)?1:0;
然后我尝试通过
获取它的 ShortMessage$xpath->query('//e:Errors[e:ErrorParameters@ParamID="ItemID"]/e:Value[.="770386906435"]/e:ShortMessage')
但由于没有找到组合过滤器的正确方法,因此得到了无效的谓词。
能否请教正确的方法?
谢谢
【问题讨论】:
标签: php xml xpath domdocument