users@jaxb.java.net

Re: How can I unmarshall a xsd:any element ?

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Mon, 30 Jul 2007 12:33:44 -0700

I think https://jaxb.dev.java.net/guide/Mapping_of__xs_any___.html would
discuss this topic.

bastral wrote:
> Hello,
>
> I have a xsd:any element (vendorExtensions) that I would like to unmarshall
> but I don't know how to do it. Do I have to create another JAXBContext
> object ?
>
> The file generated with JAXB from this xsd type
>
>
> <xsd:complexType name="MDVendorExtensions_T">
> <xsd:sequence>
> <xsd:any namespace="##any" processContents="lax" minOccurs="0"
> maxOccurs="unbounded"/>
> </xsd:sequence>
> </xsd:complexType>
>
>
>
>
>
> is :
>
>
> @XmlAccessorType(XmlAccessType.FIELD)
> @XmlType(name = "MDVendorExtensions_T", propOrder = {
> "any"
> })
> public class MDVendorExtensionsT {
>
> @XmlAnyElement(lax = true)
> protected List any;
> ..
> }
>
>
> Here is a test file :
>
> public class UnmarshalRead {
>
> public static void main( String[] args ) {
> try {
> // create a JAXBContext capable of handling classes generated
> into
> // the primer.po package
> JAXBContext jc = JAXBContext.newInstance( "primer.po" );
>
> // create an Unmarshaller
> Unmarshaller u = jc.createUnmarshaller();
>
> // unmarshal a po instance document into a tree of Java content
> // objects composed of classes from the primer.po package.
> JAXBElement<?> poElement = (JAXBElement<?>)u.unmarshal( new
> File("po.xml" ) );
> PurchaseOrderType po = (PurchaseOrderType)poElement.getValue();
>
> MDVendorExtensionsT vendorExtension = (MDVendorExtensionsT)
> poElement.getValue();
> // how can I unmarshall vendorExtension ??
>
> }
> }
>
>
>
>
> How can I unmarshall vendorExtension to get the content of new classes under
> vendorExtension element ?
>
> Thank you.


-- 
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com