XPath选择wsdl前缀命名空间(XPath select wsdl prefix namespaces)

编程入门 行业动态 更新时间:2024-10-16 20:27:40
XPath选择wsdl前缀命名空间(XPath select wsdl prefix namespaces)

我在java中使用XPath 1.0,并希望选择/检查wsdl文档命名空间,但遗憾的是没有设法做到这一点。 我想选择

命名空间xmlns =“http://schemas.xmlsoap.org/wsdl/”表示为“definitions”元素的属性 命名空间xmlns:soap =“http://schemas.xmlsoap.org/wsdl/soap/”表示为“definitions”元素的属性。

我试过XPath表达式:

“// namespace :: *”和“/ * / namespace :: *”,似乎是神秘的,因为它们返回:

"http: //www.w3.org/2001/XMLSchema", "http: //www.w3.org/XML/1998/namespace" ????? (where does it come from?)

“/ definitions / @ *”返回:

HelloService "http ://www.examples.com/wsdl/HelloService.wsdl"

有没有办法在本文档中使用xmlns:soap =“http://schemas.xmlsoap.org/wsdl/soap/”和xmlns =“http://schemas.xmlsoap.org/wsdl/”属性/命名空间XPath的? 或者其他一些工具? 检查node(attribute)或namespace值是否等于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>

I am using XPath 1.0 in java and would like to select/check wsdl document namespaces, but unfortunately did not managed to do it. I would like to select

Namespace xmlns="http://schemas.xmlsoap.org/wsdl/" represented as attribute of "definitions" element Namespace xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" represented as attribute of "definitions" element.

I tried XPath expressions:

"//namespace:: * " and "/*/namespace:: * ", which seem to be mystic, because they 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"

Is there any way to catch xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" and xmlns="http://schemas.xmlsoap.org/wsdl/" attributes/namespaces in this document using XPath? or maybe some other tools? to check if node(attribute) or namespace value is equal to schemas.xmlsoap.org/wsdl/soap (kind of correct namespace control)

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);

For the first one:

/*/namespace::*[name()='']

Result:http://schemas.xmlsoap.org/wsdl/

For the second one:

/*/namespace::*[name()='soap']

Result:http://schemas.xmlsoap.org/wsdl/soap/

You should remember to enable namespace support in 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);

更多推荐

本文发布于:2023-08-01 00:23:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1351341.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:前缀   空间   wsdl   XPath   prefix

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!