users@jaxb.java.net

Re: jaxb binding file for + <extension base="anyType"/>

From: Wolfgang Laun <wolfgang.laun_at_gmail.com>
Date: Sat, 7 Nov 2009 19:49:04 +0100

On Fri, Nov 6, 2009 at 10:48 PM, Claus Nagel <claus.nagel_at_gmail.com> wrote:

> Hi Wolfgang,
>
> I am just trying to understand how to handle a variable of type
> java.lang.Object in a JAXB class. Is it possible to read any content into
> such a generic variable even if the JAXBContext does not know about the
> corresponding XML element?
>
>
Sort of, yes. There are variations, depending on the information provided by
the XML document. I'm assuming an element which would have the schema
type xs:anyType.

If there is no information, you'll get the document element (subtree) as a
org.w3c.dom.Element.

If the element provides information about its type, e.g.
<elemAnyType xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                         xmlns:xs="http://www.w3.org/2001/XMLSchema"
                         xsi:type="xs:int">10</elemAnyType>
and JAXB knows how to handle this schema type, it will be unmarshalled into
an
object of the corresponding Java type.


> For example, suppose a schema is associated with the namespace "foo". It is
> mapped to a set of JAXB classes. One of these classes contains an attribute
> of type java.lang.Object. An XML instance document contains an element
> associated with the namespace "bar" as corresponding property element.
> Would
> this element be returned as java.lang.Object by the getter of that class
> even if the JAXBContext does not know about the namespace "bar"? Or would
> this require to explicitly bind the xsd:anyType property to DOM using a
> JAXB
> binding declaration?
>
>
A schema "wildcard" (e,g,, <xs:any/>) would result in a Java field Object
any,
annotated with @XmlanyElement, and the actual type would again be
org.w3c.dom.Element. The namespace is arbitrary. This object can be
analyzed using the DOM API, but it might also be passed to some (other)
unmarshaller, to be created from a suitable context.

-W


> Cheers,
> Claus
>
>
> Von: Wolfgang Laun [mailto:wolfgang.laun_at_gmail.com]
> Gesendet: Freitag, 6. November 2009 15:32
> An: users_at_jaxb.dev.java.net
> Betreff: Re: jaxb binding file for + <extension base="anyType"/>
>
> This customization isn't possible. If properly constrained, xs:anyType
> might
> be mapped to java.lang.Object anyway, but as it is now, you are getting
> org.w3c.dom.Element, which means that you'll get the XML document tree
> without any unmarshalling.
>
> -W
> On Fri, Nov 6, 2009 at 3:14 PM, indra_4011 <indra4011_at_gmail.com> wrote:
>
> Hi i have xsd defination
> <element name="primaryKey" nillable="false">
> <complexType mixed="false">
> <complexContent mixed="false">
> <extension base="anyType"/>
> </complexContent>
> </complexType>
> </element>
> and i using binding file to
> <jxb:bindings node="//xs:extension[@base='anyType']">
> <jxb:property>
> <jxb:baseType name="java.lang.Object"/>
> </jxb:property>
> </jxb:bindings> to generate the jaxb classes but i am unable to do
> so its giving error
> [xjc] [ERROR] Specified property customization is not used.
> Please help
> --
> View this message in context:
>
> http://old.nabble.com/jaxb-binding-file-for-%2B-%3Cextension-base%3D%22anyTy
> pe%22-%3E-tp26230531p26230531.html<http://old.nabble.com/jaxb-binding-file-for-%2B-%3Cextension-base%3D%22anyTy%0Ape%22-%3E-tp26230531p26230531.html>
> Sent from the java.net - jaxb users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>