I am having a problem when using the first way when posting to a jersey
servlet.
<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>
Is there a way in which I can force xjc to get the jaxb object generated for
OuterElem to be a XmlRootElement?
Thx
On Thu, Aug 27, 2009 at 5:14 AM, Wolfgang Laun <wolfgang.laun_at_gmail.com>wrote:
> The purpose of @XmlRootElement is to have a place for the name of the
> <element> that
> has the enclosed anonymous (in XML) type.
>
> You dont't have this when the complex type is defined separately. Here, the
> association
> between one or more elements is done in the generated ObjectFactory.
>
> This should not worry you since marshalling and unmarshalling works in both
> cases.
> -W
>
>
>
> On Wed, Aug 26, 2009 at 4:26 PM, vaidya nathan <vaidyaatdst_at_gmail.com>wrote:
>
>> 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
>>
>>
>