XPath select wsdl 前缀命名空间
XPath select wsdl prefix namespaces
我在 java 中使用 XPath 1.0 并想 select/check wsdl 文档名称空间,但不幸的是没有成功。
我愿意 select
- 命名空间 xmlns="http://schemas.xmlsoap.org/wsdl/" 表示为
"definitions" 元素的属性
- 命名空间 xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 表示为 "definitions" 元素的属性。
我试过 XPath 表达式:
"//namespace:: * "和"/*/namespace:: * ",看似神秘,
因为他们 return:
"http: //www.w3.org/2001/XMLSchema",
"http: //www.w3.org/XML/1998/namespace" ????? (where does it come from?)
"/definitions/@*" returns:
HelloService
"http ://www.examples.com/wsdl/HelloService.wsdl"
有什么方法可以使用 XPath 在本文档中捕获 xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 和 xmlns="http://schemas.xmlsoap.org/wsdl/" attributes/namespaces 吗?或者其他一些工具?检查节点(属性)或命名空间值是否等于 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>
第一个:
/*/namespace::*[name()='']
结果:http://schemas.xmlsoap.org/wsdl/
第二个:
/*/namespace::*[name()='soap']
结果:http://schemas.xmlsoap.org/wsdl/soap/
您应该记得在 java:
中启用名称空间支持
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true); //This is really important, without it that XPath does not work
DocumentBuilder db = dbf.newDocumentBuilder();
Document document = db.parse(inputSource); //inputSource, inputStream or file which contains your XML.
XPath xpath = XPathFactory.newInstance().newXPath();
String nameSpace = xpath.evaluate("/*/namespace::*[name()='']", document);
String soapNameSpace = xpath.evaluate("/*/namespace::*[name()='soap']", document);
我在 java 中使用 XPath 1.0 并想 select/check wsdl 文档名称空间,但不幸的是没有成功。 我愿意 select
- 命名空间 xmlns="http://schemas.xmlsoap.org/wsdl/" 表示为 "definitions" 元素的属性
- 命名空间 xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 表示为 "definitions" 元素的属性。
我试过 XPath 表达式:
"//namespace:: * "和"/*/namespace:: * ",看似神秘, 因为他们 return:
"http: //www.w3.org/2001/XMLSchema", "http: //www.w3.org/XML/1998/namespace" ????? (where does it come from?)
"/definitions/@*" returns:
HelloService "http ://www.examples.com/wsdl/HelloService.wsdl"
有什么方法可以使用 XPath 在本文档中捕获 xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 和 xmlns="http://schemas.xmlsoap.org/wsdl/" attributes/namespaces 吗?或者其他一些工具?检查节点(属性)或命名空间值是否等于 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>
第一个:
/*/namespace::*[name()='']
结果:http://schemas.xmlsoap.org/wsdl/
第二个:
/*/namespace::*[name()='soap']
结果:http://schemas.xmlsoap.org/wsdl/soap/
您应该记得在 java:
中启用名称空间支持DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true); //This is really important, without it that XPath does not work
DocumentBuilder db = dbf.newDocumentBuilder();
Document document = db.parse(inputSource); //inputSource, inputStream or file which contains your XML.
XPath xpath = XPathFactory.newInstance().newXPath();
String nameSpace = xpath.evaluate("/*/namespace::*[name()='']", document);
String soapNameSpace = xpath.evaluate("/*/namespace::*[name()='soap']", document);