0
我在java中使用XPath 1.0,並想選擇/檢查wsdl文檔名稱空間,但不幸的是沒有設法做到這一點。 我想選擇表示爲 「定義」 元件 XPath選擇wsdl前綴名稱空間
- 命名空間的xmlns = 「http://schemas.xmlsoap.org/wsdl/」:肥皂=「HTTP:/ /schemas.xmlsoap.org/wsdl/soap/「表示爲」definitions「元素的屬性。
我試圖XPath表達式:
「//命名空間:: *」 和 「/ * /命名空間:: *」,這似乎是神祕的, ,因爲它們返回:
"http: //www.w3.org/2001/XMLSchema", "http: //www.w3.org/XML/1998/namespace" ????? (where does it come from?)
「/定義/ @ *」 的回報:
HelloService "http ://www.examples.com/wsdl/HelloService.wsdl"
有什麼辦法可以捕獲xmlns:soap =「http://schemas.xmlsoap.org/wsdl/soap/」和xmlns =「http://schemas.xmlsoap.org/wsdl/」attributes/namespaces在這個文檔中使用XPath?或者其他一些工具?以檢查是否節點(屬性)或命名空間值等於schemas.xmlsoap.org/wsdl/soap(種類正確的命名空間控制的)
Wsdl document:
<definitions name="HelloService"
targetNamespace="http://www.examples.com/wsdl/HelloService.wsdl"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://www.examples.com/wsdl/HelloService.wsdl"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<message name="SayHelloRequest">
<part name="firstName" type="xsd:string"/>
</message>
<message name="SayHelloResponse">
<part name="greeting" type="xsd:string"/>
</message>
<portType name="Hello_PortType">
<operation name="sayHello">
<input message="tns:SayHelloRequest"/>
<output message="tns:SayHelloResponse"/>
</operation>
</portType>
<binding name="Hello_Binding" type="tns:Hello_PortType">
<soap:binding style="rpc"
transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="sayHello">
<soap:operation soapAction="sayHello"/>
<input>
<soap:body
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="urn:examples:helloservice"
use="encoded"/>
</input>
<output>
<soap:body
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="urn:examples:helloservice"
use="encoded"/>
</output>
</operation>
</binding>
<service name="Hello_Service">
<documentation>WSDL File for HelloService</documentation>
<port binding="tns:Hello_Binding" name="Hello_Port">
<soap:address location="http://www.examples.com/SayHello/"/>
</port>
</service>
</definitions>
不工作。你確定它應該適用於Xpath 1.0嗎? NodeList result =(NodeList)xpath.evaluate(「/ */namespace :: * [name()='soap']」,doc,XPathConstants.NODESET);和/ */namespace :: * [name()='']不返回任何內容。 – user34618 2015-01-20 20:07:57
我已經在http://www.xpathtester.com/xpath中測試過它。它不返回一個NodeList。我更新了答案,以顯示每個人的結果。 – 2015-01-20 20:21:35
它寫在問題「我正在使用Java中的XPath 1.0 ......」 – user34618 2015-01-20 20:22:46