users@jaxb.java.net

Unexpected end element

From: Vallamshettla, Anand <Anand.Vallamshettla_at_tgslc.org>
Date: Mon, 7 Feb 2005 14:43:24 -0600

 

We are facing problem unmarshalling a XML file where one required
attribute is missing even with validation turned off. (Using jwsdp1.5)

 

We are getting error messages "Unexpected element". I debugged the
generated code and found that it is looking for a required attribute and
it didn't find in XML; that's the reason it starts throwing all those
unexpected elements messages i.e using the Discard handler.

If there is and element or attribute that is required and JAXB couldn't
find it, then it stops processing one way the other and ends up trashing
the file.

 

 

Ex:

 

Our schema is

     

    <xs:element name="A" type="AType" minOccurs="0"/>

            <xs:complexType name="AType">

                        <xs:sequence>

                                    <xs:element name="Name"
type="NameType" minOccurs="0"/>

                        </xs:sequence>

                        <xs:attribute name="Number" type="xs:integer"
use="required"/>

            </xs:complexType>

 

and XML is

 

<A>

 <Name>abcd</Name>

</A>

 

Where attribute "Number" is missing. JAXB gives error messages

Unexpected element {}: Name

javax.xml.bind.JAXBException: Unexpected end element {}:A

 

Isn't it validating the structure of the XML against schema?

We ran the same XML using XMLBeans with validations turned off, it just
worked fine.

Even though JAXB is much 4 times faster than XMLBeans, this may be a
huge problem with JAXB for customers like us.

We would get 1000's of records; and may be 2 or 3 records might have
this problem - in this case we would want to read the file but discard
just that record.

And the error message is not too clear -- it should have give message
something like "Expecting required attribute 'Number' rather than
unexpected element {}: Name."

 

 

Are there any options available on JAXB compilation that would make
parsing flexible or is it just the way JAXB works?

(I tried -nv option on compilation and also turned off validations on
SAX parser while testing).

 

PS: When I turn on validation, we run into StackOverFlow exception -
tried all sorts of memory settings - no luck. It's a huge schema though.

 

 

Anand