下面是一個XML性反應,我試圖用soapui腳本(常規)斷言探索:爲什麼這個XPath(所有到目標的節點)都無法看到響應中的元素(使用SoapUI)?
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<myInfoResponse xmlns="http://test.test.test.test">
<pc>1234223234</pc>
<item>
<sl>val1</sl>
<he>val2</he>
<ko>val3</ko>
<fo>val4</fo>
<ok>val5</ok>
<di>val6</di>
</item>
...
爲什麼我不能讓pc
節點與價值:
def holder = new XmlHolder(messageExchange.responseContentAsXml)
holder.getNodeValue("/S:Envelope/S:Body/myInfoResponse/pc")
// Output: null
holder.getNodeValue("/S:Envelope/S:Body/myInfoResponse[1]/pc[1]")
// Output: null
而且我可以得到價值XPath
holder.getNodeValue("/S:Envelope/S:Body/*[1]/*[1]")
// Output: 1234223234
holder.getNodeValue("/S:Envelope/S:Body/*[1]/*[2]/*[4]")
// Output: val4
爲什麼?
http://www.edankert.com/defaultnamespaces.html – Rao
因爲默認的命名空間。如果你想獲取與持有者無關的名稱空間,那麼'holder.getNodeValue(「/ S:Envelope/S:Body/*:myInfoResponse/*:pc」)' –