Как связать схему с jaxb2 для дублированного имени элемента - PullRequest
0 голосов
/ 25 октября 2018

Я пытаюсь создать классы Java из нескольких файлов XSD.В этих файлах схем есть несколько complexType или элементы с одинаковыми именами в разных схемах.

Обратите внимание, что я не могу изменить схемы.

Я создал файл привязки, но яя все еще получаю эту ошибку

EXAMPLE_QualifyRQ.xsd;... 'myelement' уже определен

Есть ли что-то, что мне не хватает в моей конфигурации?

Все схемы находятся в 1 каталоге, например:

xsd:

  • EXAMPLE_QualifyRS.xsd
  • EXAMPLE_QualifyRQ.xsd
  • EXAMPLE_PurchaseRQ.xsd
  • EXAMPLE_CommonTypes.xsd

EXAMPLE_QualifyRS.xsd

<xs:schema xmlns="http://www.example.org/EXAMPLE/2007/00" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/EXAMPLE/2007/00"
 elementFormDefault="qualified" version="1.002" id="EXAMPLE2016.1">
     <xs:include schemaLocation="EXAMPLE_CommonTypes.xsd"/>
     <xs:element name="myelement">...</xs:element>

EXAMPLE_QualifyRQ.xsd

<xs:schema xmlns="http://www.example.org/EXAMPLE/2007/00" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/EXAMPLE/2007/00"
 elementFormDefault="qualified" version="1.002" id="EXAMPLE2016.1">
     <xs:include schemaLocation="EXAMPLE_CommonTypes.xsd"/>
     <xs:element name="myelement">...</xs:element>

EXAMPLE_PurchaseRQ.xsd

<xs:schema xmlns="http://www.example.org/EXAMPLE/2007/00" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/EXAMPLE/2007/00" elementFormDefault="qualified" version="1.001" id="EXAMPLE2016.1">
    <xs:include schemaLocation="EXAMPLE_CommonTypes.xsd"/>
    <xs:include schemaLocation="EXAMPLE_SimpleTypes.xsd"/>
    <xs:element name="myelement">...</xs:element>

А вот как я генерируюМой класс в Maven

<plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>jaxb2-maven-plugin</artifactId>
                <version>2.4</version>
                <executions>
                    <execution>
                        <id>example-schema</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>xjc</goal>
                        </goals>
                        <configuration>
                            <xsdPathWithinArtifact>xsd</xsdPathWithinArtifact>
                            <addGeneratedAnnotation>true</addGeneratedAnnotation>
                            <laxSchemaValidation>true</laxSchemaValidation>
                            <laxSchemaValidation>true</laxSchemaValidation>
                            <readOnly>true</readOnly>
                            <verbose>true</verbose>
                            <sources>
                                <source>src/main/resources/xsd</source>
                            </sources>
                            <xjbSources>
                                <xjbSource>src/main/resources/xjb</xjbSource>
                            </xjbSources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

И мои привязки

    <?xml version="1.0" encoding="UTF-8"?>
    <bindings version="2.1"
              xmlns="http://java.sun.com/xml/ns/jaxb"
              xmlns:xs="http://www.w3.org/2001/XMLSchema"
              xmlns:xsd="http://www.w3.org/2001/XMLSchema"
              xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
              extensionBindingPrefixes="xjc">
        <globalBindings>
            <serializable uid="1"/>
            <xjc:javaType name="java.time.LocalDateTime" xmlType="xs:dateTime" adapter="com.example.adapter.LocalDateTimeAdapter"/>
            <xjc:javaType name="java.time.LocalDate" xmlType="xsd:date" adapter="com.example.adapter.LocalDateAdapter"/>
        </globalBindings>

        <bindings schemaLocation="../xsd/EXAMPLE_QualifyRS.xsd" node="/xs:schema">
            <schemaBindings>
                <package name="com.example.qualify.response"/>
            </schemaBindings>
            <bindings node="//xs:element[@name='myelement']">
                <class name="QualifyMyElement"/>
            </bindings>
        </bindings>

<bindings schemaLocation="../xsd/EXAMPLE_QualifyRQ.xsd" node="/xs:schema">
            <schemaBindings>
                <package name="com.example.qualify.request"/>
            </schemaBindings>
            <bindings node="//xs:element[@name='myelement']">
                <class name="QualifyMyElement"/>
            </bindings>
        </bindings>

        <bindings schemaLocation="../xsd/EXAMPLE_PurchaseRQ.xsd" node="/xs:schema">
            <schemaBindings>
                <package name="com.example.purchase"/>
            </schemaBindings>
            <bindings node="//xs:element[@name='myelement']">
                <class name="PurchaceMyElement"/>
            </bindings>
        </bindings>
    </bindings>
...