Binding JAXB XJC两个声明会导致冲突。不能接受自定义绑定
我想从这个模式文件生成JAXB类: 我使用自定义绑定解决了由导入的mods-3-1.xsd引起的两个命名冲突,如下所示:Binding JAXB XJC两个声明会导致冲突。不能接受自定义绑定,binding,jaxb,xsd,xjc,Binding,Jaxb,Xsd,Xjc,我想从这个模式文件生成JAXB类: 我使用自定义绑定解决了由导入的mods-3-1.xsd引起的两个命名冲突,如下所示: <jxb:bindings xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:jxb="http://java.sun.com/xml/ns/jaxb" version="2.1"> <jxb:bindings schemaLocation="http://www.loc.gov/standards
<jxb:bindings xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb" version="2.1">
<jxb:bindings schemaLocation="http://www.loc.gov/standards/mods/v3/mods-3-1.xsd">
<jxb:bindings
node="//xsd:complexType[@name='relatedItemType']/xsd:attribute[@name='type']">
<jxb:property name="type2" />
</jxb:bindings>
<jxb:bindings
node="//xsd:attributeGroup[@name='language']/xsd:attribute[@name='lang']">
<jxb:property name="lang2" />
</jxb:bindings>
<jxb:bindings
node="//xsd:complexType[@name='titleInfoType']/xsd:complexContent/xsd:extension/xsd:attribute[@name='type']">
<jxb:property name="type3" />
</jxb:bindings>
<jxb:bindings
node="//xsd:complexType[@name='nameType']/xsd:attribute[@name='type']">
<jxb:property name="type4" />
</jxb:bindings>
<jxb:bindings
node="//xsd:complexType[@name='unstructuredText']/xsd:simpleContent/xsd:extension/xsd:attribute[@name='type']">
<jxb:property name="type5" />
</jxb:bindings>
</jxb:bindings>
</jxb:bindings>
当我添加另一个自定义绑定时
<jxb:bindings schemaLocation="http://digir.net/schema/conceptual/darwin/manis/1.21/darwin2.xsd">
<jxb:bindings
node="//xsd:element[@name='requiredList' and @substitutionGroup='digir:requiredList']">
<jxb:property name="requiredList2" />
</jxb:bindings>
</jxb:bindings>
有什么办法解决这个问题吗?一个很好的答案是:
简而言之,使用
定制。我们可以如下使用。我得到了相同的错误,并使用factoryMethod解决
命令:xjc-dsrc-extension-bdemo.xjb demo.xsd
demo.xjb
================
<jxb:bindings
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
version="2.1">
<jxb:bindings schemaLocation="demo.xsd">
<jxb:bindings node="//xs:complexType[@name='itemType']">
<jxb:factoryMethod name="Item"/>
</jxb:bindings>
</jxb:bindings>
</jxb:bindings>
demo.xsd
===============
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
jaxb:version="2.1">
<xs:complexType name="itemType">
<xs:annotation>
<xs:appinfo>
<jaxb:class name="Item"/>
</xs:appinfo>
</xs:annotation>
<xs:attribute name="id" type="xs:string" use="required"/>
</xs:complexType>
</xs:schema>
demo.xjb
================
demo.xsd
===============
parsing a schema...
[ERROR] compiler was unable to honor this property customization. It is attached to a
wrong place, or its inconsistent with other bindings.
line 34 of file:/C:/git/charaparser%20-%20Copy/resources/io/darwinCore/mods-3-1-
bindings.xml
[ERROR] (the above customization is attached to the following location in the schema)
line 468 of http://digir.net/schema/conceptual/darwin/manis/1.21/darwin2.xsd
Failed to parse a schema.
demo.xjb
================
<jxb:bindings
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
version="2.1">
<jxb:bindings schemaLocation="demo.xsd">
<jxb:bindings node="//xs:complexType[@name='itemType']">
<jxb:factoryMethod name="Item"/>
</jxb:bindings>
</jxb:bindings>
</jxb:bindings>
demo.xsd
===============
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
jaxb:version="2.1">
<xs:complexType name="itemType">
<xs:annotation>
<xs:appinfo>
<jaxb:class name="Item"/>
</xs:appinfo>
</xs:annotation>
<xs:attribute name="id" type="xs:string" use="required"/>
</xs:complexType>
</xs:schema>