users@jaxb.java.net

How can I unmarshall a xsd:any element ?

From: bastral <baptistebesson_at_yahoo.fr>
Date: Thu, 12 Jul 2007 03:05:48 -0700 (PDT)

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.
-- 
View this message in context: http://www.nabble.com/How-can-I-unmarshall-a-xsd%3Aany-element---tf4067146.html#a11556934
Sent from the java.net - jaxb users mailing list archive at Nabble.com.