XPath评估结果为空目标节点

时间:2014-06-13 18:13:49

标签: xpath maven-jaxb2-plugin

我正在尝试使用WSDL并使用maven-jaxb2-plugin生成绑定类。

WSDL就是这个,

<wsdl:definitions>
  <wsdl:types>
  ...
  </wsdl:types>
  ...
  <wsdl:message name="IServiceWeb_GetPaymentInfo_InputMessage">
    <wsdl:part name="parameters" element="tns:GetPaymentInfo"/>
  </wsdl:message>
  ...
  <wsdl:portType name="IServiceWeb">
      ...
      <wsdl:operation name="GetPaymentInfo">
         <wsdl:input wsaw:Action="*****" message="tns:IServiceWeb_GetPaymentInfo_InputMessage"/>
         <wsdl:output wsaw:Action="*****" message="tns:IServiceWeb_GetPaymentInfo_OutputMessage"/>
       </wsdl:operation>
  </wsdl:portType>

当我最初尝试生成类时,我收到了此错误,

org.xml.sax.SAXParseException: A class/interface with the same name "org.package.GetPaymentInfoResponse" is already in use. Use a class customization to resolve this conflict.

我添加了一个带有此内容的binding.xjb文件,

<?xml version="1.0" encoding="UTF-8"?>
<bindings xmlns="http://java.sun.com/xml/ns/jaxb" xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
    xsi:schemaLocation=" http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" version="2.1">
    <bindings
        node="wsdl:definitions/wsdl:message[@name='IServiceWeb_GetPaymentInfo_OutputMessage']/wsdl:part[@name='parameters']">
        <class name="GetPaymentInfoOutputMessage" />
    </bindings>
</bindings>

我得到的错误是,

com.sun.istack.SAXParseException2: XPath evaluation of "wsdl:definitions/wsdl:message[@name='IServiceWeb_GetPaymentInfo_OutputMessage']/wsdl:part[@name='parameters']" results in empty target node

有关生成这些文件的建议吗?

修改 我声明了错误的节点,IServiceWeb_GetPaymentInfo_InputMessage应该是IServiceWeb_GetPaymentInfo_InputMessage,修正后的绑定是,

<?xml version="1.0" encoding="UTF-8"?>
<bindings xmlns="http://java.sun.com/xml/ns/jaxb" xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
    xsi:schemaLocation=" http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" version="2.1">
    <bindings
        node="wsdl:definitions/wsdl:message[@name='IServiceWeb_GetPaymentInfo_InputMessage']/wsdl:part[@name='parameters']">
        <class name="GetPaymentInfoOutputMessage" />
    </bindings>
</bindings>

,错误信息是,

com.sun.istack.SAXParseException2: XPath evaluation of "wsdl:definitions/wsdl:message[@name='IServiceWeb_GetPaymentInfo_InputMessage']/wsdl:part[@name='parameters']" results in empty target node

3 个答案:

答案 0 :(得分:2)

<强>解决

我的绑定文件缺少schemaLocation属性,该属性给出了特定XSD的导入值(如此处所示),以及我特定架构的正确XPath表达式,

<bindings schemaLocation="https://myURI/mySchema.xsd">
    <bindings
        node="//xs:complexType[@name='GetPaymentInfoResponse']">
        <class name="GetPaymentInfoResponseType" />
    </bindings>
</bindings>

此外,使用JDK 1.6,我需要d / l并将jaxb 2.2罐添加到我的jdk认可的lib目录中,如此处所述,http://cxf.apache.org/docs/23-migration-guide.html

使用{JAVA_HOME} /bin/wsimport.exe或使用jaxws-maven-plugin这两种备用方法之一导致使用此配置解决了“使用类自定义来解决此冲突”错误

                <configuration>
                <args>
                    <arg>-B-XautoNameResolution</arg>
                    </args>
                            </configuration>

但不会像上面那样使用背书罐。

因此,我的类已生成,现在正在运行Web服务。 Maven是一种生成类文件的好方法。

答案 1 :(得分:0)

您的绑定文件应声明与您在XPath表达式中使用的wsdl 前缀相关联的XPath表达式的命名空间:

<bindings xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
          xmlns="http://java.sun.com/xml/ns/jaxb" version="1.0"
          node="wsdl:definitions/wsdl:message[@name='IServiceWeb_GetPaymentInfo_OutputMessage']/wsdl:part[@name='parameters']">
    <class name="GetPaymentInfoInputMessage" />
</bindings>

如果您有使用其他命名空间的XPath表达式(例如XML架构类型,SOAP信封等),则必须声明它们并使用声明的前缀来限定每个选择器。任何引用属于命名空间一部分的元素的XPath选择器都必须加前缀(即使在源中,命名空间被声明为默认值)。

答案 2 :(得分:0)

在您的代码段中,节点为

<wsdl:message name="IServiceWeb_GetPaymentInfo_InputMessage">

在绑定文件中,您调用了包含

的xpath
<bindings
    node="wsdl:definitions/wsdl:message[@name='IServiceWeb_GetPaymentInfo_OutputMessage']/wsdl:part[@name='parameters']">

尝试更改绑定文件中的xpath以反映IServiceWeb_GetPaymentInfo_InputMessage

<bindings
    node="wsdl:definitions/wsdl:message[@name='IServiceWeb_GetPaymentInfo_InputMessage']/wsdl:part[@name='parameters']">