users@jaxb.java.net

Re: can someone help me understand namespaces in the context of (un)marshalling?

From: jon gold <dev_at_samizdatdigital.org>
Date: Thu, 17 Feb 2005 16:15:13 -0800

Kohsuke Kawaguchi wrote:
> jon gold wrote:
>
>> i'm having a lot of trouble lately trying to unmarshal documents, and
>> also not fully understanding the results of marshalling.
>>
>> trying to unmarshal
>>
>> <?xml version="1.0"?>
>> <foo xmlns="http://somens">
>> <bar>...</bar>
>> ...
>> </foo>
>>
>> fails with 'unexpected element {http://somens}:bar', but succeeds when
>> the document contains
>>
>> <bar xmlns="">...</bar>
>
>
> Depending on the schema, that seems like a correct behavior to me. It
> really depends on how "bar" is declared.
>

bar is declared in the same schema as foo. ie, i have

<schema targetNamespace="http://somens"
        xmlns:this="http://somens" ...>
        
        <complexType name="BarType">...</

        <complexType name="FooType">
                <sequence>
                        <element name="bar" type="this:BarType"/>
                        ...
                </
        </

        <element name="foo" type="this:FooType"/>
</

> The change you made was a very significant change --- it changed the
> namespace URI of the bar element. So if one was valid, the other is
> definitely invalid.
>

that's why i was surprised. the change (not using createElementNS) gives
me a bar which is not in any namespace, which marshals okay, but i would
think *shouldn't*, since the bar i want is in the somens namespace.