0

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>>();
        }
        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

M.Torres
  • 119
  • 1
  • 1
  • This has nothing to do with maven-jaxb2-plugin, the plugin is merely an XJC wrapper. What is the error, actually? – lexicore Jun 10 '11 at 06:22
  • When two elements has the same name in a complexType, the class not is correctly generated (because is not possible to create two java variable with same name in a class) and compile goal of maven not show this issue. The problem is that I have many XSD files to validate. I would like automatic check all files and I think this plugin could make it for me. Tks. – M.Torres Jun 10 '11 at 18:53
  • "The problem is that I have many XSD files to validate. I would like automatic check all files and I think this plugin could make it for me." If validating is your main goal, please see my answer. – micfra Nov 03 '11 at 12:31

1 Answers1

0

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.

micfra
  • 2,780
  • 1
  • 23
  • 34
  • Dear Micfra, thanks for your answer. I will test it and see if it works. I not need more, but it's good know about this. – M.Torres Dec 04 '11 at 00:39