将xml解析为正则表达式值

时间:2015-10-26 09:05:00

标签: xml xpath

我有以下XML:

<?xml version="1.0"?>
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"         xmlns:a="http://www.w3.org/2005/08/addressing">
<s:Header>
     <a:Action s:mustUnderstand="1">http:///version1/IItemSaleService     /NewCartForTransactionsResponse</a:Action>
      <ActivityId xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics" CorrelationId="7ccc7b80-b4e8-4fd2-ae61-625b06870191">5b379c02-9288-4e5a-a993-076bf575e5dc</ActivityId>
 </s:Header>
 <s:Body>
 <NewCartForTransactionsResponse xmlns="sservice/itemsale/version1">
<NewCartForTransactionsResult xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<ActionCodes/>
<Cart>
    <BarCodeData>22100245107700005684000000002610153</BarCodeData>
    <CartId>
        <HashBasedMessageAuthenticationCode>42</HashBasedMessageAuthenticationCode>
        <ID>1012451-77-5684</ID>
      ....
</s:Envelope>

我想得到节点的价值     (1012451-77-5684)。

使用

//ID[0]/text()

不起作用。

任何提示?

2 个答案:

答案 0 :(得分:0)

尝试使用XPath local-name

// * [本地名称()=&#39; ID&#39;]

答案 1 :(得分:0)

这是如何工作的,最终的语法是什么?

您使用... .check(xpath(“ /// text()”)。find.saveAs(“ id”))

而不是... .check(xpath(“ // ID [0] / text()”)。find.saveAs(“ id”))

相关问题