我使用http://www.freeformatter.com/xpath-tester.html来获取UserId
值
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:paf="http://paf.mycompany.com/">
<soapenv:Header/>
<soapenv:Body>
<paf:requestpafBean>
<!--Optional:-->
<arg0>
<!--Optional:-->
<UserId>?</UserId>
<!--Optional:-->
<DateNow>?</DateNow>
</arg0>
</paf:requestpafBean>
</soapenv:Body>
</soapenv:Envelope>
测试这个XPath表达式:
//paf:UserId[1]/@text
为什么我找不到比赛?
最佳答案
以下XPath表达式,
//UserId/text()
将根据要求选择
?
。笔记:
UserId
不在命名空间中,因此您不需要paf:UserId
。如果有多个
UserId
,则可以将UserId[1]
添加到表达。
text
上没有UserId
属性,因此您不需要UserId/@text
,但是text()
下有一个UserId
节点,因此您确实需要UserId/text()
。如果
UserId
下可能还有其他标记,则可能需要它的字符串值
string(//UserId)
,而不是选择其子文本节点。
关于xml - 为什么我的XPath表达式不匹配?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35732595/