【发布时间】:2016-08-01 16:41:20
【问题描述】:
我正在尝试使用wsimport 通过运行以下命令将 WSDL 文件转换为 Java 代码(应该可以在任何人的机器上运行):
wsimport https://webservices-uatprod.dhisco.com/OTAHotelDescriptiveInfo/web_services?WSDL -J-Djavax.xml.accessExternalDTD=all -J-Djavax.xml.accessExternalSchema=all -B-XautoNameResolution -Xnocompile
但是,我不断收到此错误:
[ERROR] 'lang' is already defined
line 93 of http://www.w3.org/2001/03/xml.xsd
[ERROR] (related to above error) the first definition appears here
line 43 of http://www.w3.org/2001/xml.xsd
[ERROR] 'space' is already defined
line 102 of http://www.w3.org/2001/03/xml.xsd
[ERROR] (related to above error) the first definition appears here
line 89 of http://www.w3.org/2001/xml.xsd
[ERROR] 'base' is already defined
line 109 of http://www.w3.org/2001/03/xml.xsd
[ERROR] (related to above error) the first definition appears here
line 113 of http://www.w3.org/2001/xml.xsd
[ERROR] 'specialAttrs' is already defined
line 117 of http://www.w3.org/2001/03/xml.xsd
[ERROR] (related to above error) the first definition appears here
line 157 of http://www.w3.org/2001/xml.xsd
我花了几个小时在谷歌上搜索这个以尝试找到解决方案。我比较确信我需要用-b binding.xml 标志指定一个绑定文件。
但是,我很难弄清楚如何创建该绑定文件。这是我尝试过的:
binding.xml
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xsd="http://www.w3c.org/2001/XMLSchema"
xmlns:xs="http://www.w3.org/2001/03/xml.xsd"
jaxb:version="2.0">
<jaxb:bindings schemaLocation="http://www.w3.org/2001/xml.xsd">
<jaxb:bindings node="//xs:attribute[@name='lang']">
<jaxb:property name="langAttribute"/>
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>
然后,有了这个,我尝试通过以下方式运行绑定文件:
wsimport https://webservices-uatprod.dhisco.com/OTAHotelDescriptiveInfo/web_services?WSDL -J-Djavax.xml.accessExternalDTD=all -J-Djavax.xml.accessExternalSchema=all -B-XautoNameResolution -Xnocompile -b binding.xml
现在我得到了:
[ERROR] XPath evaluation of "//xs:attribute[@name='lang']" results in empty target node
line 6 of file:/Users/name/git/foo/bar/src/main/resources/wsdl/binding.xml
我已经尝试了绑定文件的 XPath 的许多其他组合...我想我需要将所有元素的属性从“lang”重命名为其他名称,但我真的很难弄清楚。
提前感谢您的帮助!
解决方案更新:
我通过在本地下载架构克服了这个错误,并且无论在哪里引用 schemaLocation="http://www.w3.org/2001/03/xml.xsd" 和 schemaLocation="http://www.w3.org/2001/xml.xsd",我都编辑了 XML 以指向文件系统上文件的本地副本。
即打开引用这些文件的每个 *.xsd 文件,并从以下内容更新每一行:
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="http://www.w3.org/2001/xml.xsd"/>
到这里:
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="./xml.xsd"/>
之后,它能够使用上面的wsimport 语法生成 Java 类(确实需要一个小的绑定文件,但这与供应商定义的类有关)。
【问题讨论】:
标签: java xpath jaxb xjc wsimport