users@jaxb.java.net

Re: Unmarshal exception..

From: Enrico Zini <zinie_at_cs.unibo.it>
Date: Fri, 08 Nov 2002 01:09:18 +0100

On Thu, Nov 07, 2002 at 03:29:31PM -0700, Bill Marcum wrote:

> I've written a schema, which cleanly compiles. If I instantiate one
> of these objects, use the 'set' methods to populate it, marshal it to
> a data stream, and then attempt to use the Unmarshaller to unmarshal
> it, I get an exception : javax.xml.bind.UnmarshalException: Unexpected
> element ....
>
> I'm hoping this is because I'm doing something wrong, but it seems
> more likely it's a bug in JAXB, right? That is, JAXB said the schema
> was valid, JAXB wrote the XML, and now JAXB says the XML is invalid.

I had the very same problem and tried validating the structure before
marshalling, but it gave no errors. I've then tried to validate the
marshalled XML file against its schema (using the Counter app from
xerces2), but again, it was valid. JAXB was producing valid XML that it
could not read back.

I've solved the problem eliminating the targetNamespace directive from
the schema, so that the marshalled XML file worked well without the need
to qualify its parameters (i.e. without the ns1: stuff).

I'm still not an expert in XML namespaces, so I can't tell if it's a bug
or it was a flawed use of namespaces, but the obscurity of the error
message can certainly qualify as a bug. It left me quite resourceless,
for a while: before removing the namespace directives, I've even tried
unmarshalling an XML file containing only a single valid root element,
and I still got the "Unexpected element" UnmarshalException.


Bye,

Enrico

--
GPG key: 1024D/797EBFAB 2000-12-05 Enrico Zini <enrico_at_debian.org>