users@jaxb.java.net

Generating XmlRootElement from xsd

From: vaidya nathan <vaidyaatdst_at_gmail.com>
Date: Wed, 26 Aug 2009 09:26:55 -0500

I am using xjc to generate jaxb annotated java objects from schema and have
a question related to it
How are these two way different?

1. <xs:element name="OuterElem" type="tns:ComplexType" />

   <xs:complexType name="ComplexType">
     <xs:sequence>
        <xs:element name="simpleType" type="ns1:<<SomeOther type>>"/>
       </xs:sequence>
 </xs:complexType>

2. <xs:element name="OuterElem">
  <xs:complexType>
   <xs:sequence>
    <xs:element name="comment" type="xs:string" maxOccurs="unbounded"/>
   </xs:sequence>
  </xs:complexType>
 </xs:element>

The second one is generating the @XmlRootElement(name = "OuterElem") whereas
the first one is not when it goes through xjc.
1. Why is xjc not generating the XmlRootElement for the first way too even
though it looks very similiar to the second way.
2. Is there a way to specify that the element should be a root element(I
tried root="true" as specified from some website but it rendered it invalid)
so that the java object has a
@XmlRootElement(name = "RootElem")

Build
=====
jdk 1.5
in my pom.xml I am using
<build>
        <plugins>
            <plugin>
                <groupId>com.sun.tools.xjc.maven2</groupId>
                <artifactId>maven-jaxb-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>

                <configuration>
                    <removeOldOutput>true</removeOldOutput>

<generateDirectory>src/generated-sources</generateDirectory>
                    <includeSchemas>
                        <includeSchema>**/*.xsd</includeSchema>
                    </includeSchemas>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.5</source>
                    <removeOldOutput>true</removeOldOutput>

<generateDirectory>src/generated-sources</generateDirectory>
                    <generatePackage>/</generatePackage>
                    <includeSchemas>
                        <includeSchema>**/*.xsd</includeSchema>
                        <includeSchema>**/*.dtd</includeSchema>
                    </includeSchemas>
                </configuration>
            </plugin>
        </plugins>
    </build>

and my jaxb dependency in the pom is

<dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-impl</artifactId>
            <version>2.1.10</version>
        </dependency>


Regards