Namespace declarations inherit, i.e. all elements in your XML are actually
in namespace xxxx. That's how XML namespaces work. That means your Java
class in turn needs to have "namespace = "xxx"" on all @XmlElement
annotations to parse them. Potentially you can make this the default using
an @XmlSchema annotation on the package but I don't remember. It's been a
while.
On Thu, Apr 8, 2010 at 5:40 PM, magic creative <magiccreative_at_gmail.com>wrote:
> Hi,
>
> I have a small problem when unmarshalling with jaxb. The xml string that I
> use to unmarshal has a main element with namespace defined (<MainElement
> xmlns="xxxx") but all other elements do not have any xmlns attribute. When I
> annotate the class with @XmlElement, JaxB expects input in the form
> <property name = "foo" xmlns="">. If the property is simply <property name =
> "foo"> I do not get exception but it is unmarshalled to null in the java
> class instead of the real property value.
>
> Is it possible to annotate XmlElement so that JaxB would simply accept
> <property name = "foo">.
>
> If it is not I am thinking of a SAX Filter which would add the namespace
> definition to each property but I do not find this solution very elegant.
>
> Greetings
>