users@jaxb.java.net

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

From: Davide Gesino <williamkidd_at_libero.it>
Date: Fri, 28 Sep 2007 02:32:05 -0700 (PDT)

I am encountering the same problem.
How can I also mashall an object in the list of generic object?
I have tried mashalling a string encapsulating it in a JAXBElement.
Is it correct?
Anyway the unmarhaller does no t work!!!
I get the object that is a xerces NMElement, but I an not able to recover
the class inside this element.

David



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.
>

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