开发者

duplicate element not is detected with maven jaxb/jaxb2 plugin

开发者 https://www.devze.com 2023-03-12 08:26 出处:网络
I\'m using maven-jaxb-plugin and maven-jaxb2-plugin to compile a xsd file that has two elements with same name, but the code compiles without throws an error. The generated class don\'t have the co-re

I'm using maven-jaxb-plugin and maven-jaxb2-plugin to compile a xsd file that has two elements with same name, but the code compiles without throws an error. The generated class don't have the co-related properties. See the generated class:

...

*         <element name="elementName" type="{http://namespace}typeElementName"/>
*         <element name="elementName" type="{http://namespace}typeElementName"/>

public class TypeNameType {
    @XmlElementRefs({
        @XmlElementRef(name = "elementName", namespace = "http://namespace", type = JAXBElement.class)
    })

    protected List<JAXBElement<? extends Serializable>> content;

    public List<JAXBElement<? extends Serializable>> getContent() {
        if (content == null) {
            content = new ArrayList<JAXBElement<? extends Serializable>>();开发者_StackOverflow
        }
        return this.content;
    }

}

and XSD:

<schema elementFormDefault="qualified"
targetNamespace="http://namespace"
    xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://namespace">

    <complexType name="typeNameType">
        <sequence>
            <element minOccurs="1" maxOccurs="1" name="elementName" type="string" />
            <element minOccurs="1" maxOccurs="1" name="elementName" type="string" />
        </sequence>
    </complexType>
</schema>

Can anybody help me with this issue?

Tks!

Marcelo


Validating a bunch of xml files and xsd files as well, can be done by the xml-maven-plugin:

  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>xml-maven-plugin</artifactId>
    <version>1.0</version>
    <executions>
      <execution>
        <goals>
          <goal>validate</goal>
        </goals>
      </execution>
    </executions>
    <configuration>
      <validationSets>
        <validationSet>
          <dir>src/main/xsd</dir>
          <systemId>http://www.w3.org/2001/XMLSchema.xsd</systemId>
        </validationSet>
      </validationSets>
    </configuration>
  <plugin>

Havin all your xsd files below src/main/xsd the plugin will validate them against http://www.w3.org/2001/XMLSchema.xsd by runing mvn xml:validate. You should download the XMLSchema.xsd to your project to make validation faster and to skip the request to w3.org.

0

精彩评论

暂无评论...
验证码 换一张
取 消