java - xpath 错误 : null on jaxb external bindings file

标签 java xpath jaxb jax-ws wsimport

我正在尝试使用 wsimport 为外部 Web 服务的客户端生成 Java 代码。

我已经创建了一个外部绑定(bind)文件,因为存在阻止 wsimport 工作的重复属性名称。我在第 4 行收到错误 xpath error: null

这是我的绑定(bind)文件:

<jxb:bindings version="2.0"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<jxb:bindings wsdlLocation="http://XXXXX.net/WebService/XXXXX.chc?wsdl" node="/xs:schema">

<jxb:bindings node="//xs:element[@name='elementname']">
    <jxb:bindings node="//xs:element[@name='Option']">
        <jxb:bindings node="//xs:complexType">
            <jxb:bindings node=".//xs:attribute[@name='value']">
                <jxb:property name="ValueToFixError1" />
            </jxb:bindings>
        </jxb:bindings>
    </jxb:bindings>
</jxb:bindings>
</jxb:bindings>
</jxb:bindings>

我尝试用 schemaLocation 替换 wsdlLocation 并得到一个不同的错误: “http://XXXXX.net/WebService/XXXXX.chc?wsdl” 不是此汇编的一部分。这是“http://XXXXX.net/WebService/XXXXX.chc?wsdl#types?schema1”的错误吗?同样在第 4 行,但是将 #types?schema1 添加到 url 只会让我回到原来的错误。

所以我尝试按照建议使用 jaxws,但我遇到了同样的错误:

<jaxws:bindings
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
wsdlLocation="http://XXXXX.net/WebService/XXXXX.chc?wsdl">
    <jaxws:bindings node="//definitions/types/xs:schema">
    <jaxb:bindings node="//xs:element[@name='elementname']">
        <jaxb:bindings node="//xs:element[@name='Option']">
            <jaxb:bindings node="//xs:complexType">
                <jaxb:bindings node=".//xs:attribute[@name='value']">
                    <jaxb:property name="ValueToFixError1" />
                </jaxb:bindings>
            </jaxb:bindings>
        </jaxb:bindings>
    </jaxb:bindings>
    </jaxws:bindings>
</jaxws:bindings>

编辑:添加部分 wsdl:

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:cc="urn:cc" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="urn:cc">
<types>
    <xs:schema targetNamespace="urn:cc" xmlns:cc="urn:cc" elementFormDefault="qualified" attributeFormDefault="qualified">    

最佳答案

使用 apache cxf 而不是 wsimport 解决了我的问题,但在我最初的方法中也存在一些问题。

这是最终起作用的:

<jxb:bindings version="2.0" 
xmlns:jxb="http://java.sun.com/xml/ns/jaxb" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:xs="http://www.w3.org/2001/XMLSchema"
wsdlLocation="http://XXXXX.net/WebService/XXXXX.chc?wsdl"
node="//xs:schema">

<jxb:bindings node="//xs:element[@name='elementname']//xs:element[@name='Option']//xs:complexType">
    <jxb:bindings node=".//xs:attribute[@name='value']">
      <jxb:property name="ValueToFixError1" />
    </jxb:bindings>
</jxb:bindings>
</jxb:bindings>

节点不应该嵌套,而是全部在一行上使用//。

关于java - xpath 错误 : null on jaxb external bindings file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24630989/

相关文章:

java - 寻找免费且简单的(自动)生成 JUnit 测试的方法

java - Jaxb2Marshaller 如何保存 JAXBContext

java - JAXB从XML字符串到Java对象,出了什么问题?

json - 忽略 jax-rs 中传入的 json 元素

html - 使用包含文本的 XPath 1.0 选择所有最深的节点,忽略标记

python - 如何在源代码(Xpath)中查找特定字符串并提取后续文本?

java在递归函数中保留信息

java - 什么时候以及为什么我们必须实现 Comparable 接口(interface)?

java - 在同一对象中测试方法时如何模拟对象中的方法

xpath - 在 Google 工作表中创建函数以获取我的外部 IP 地址