users@jaxb.java.net

Re: Problem marshaling <xs:any> element with attributes

From: Anand Navale <naanand_at_novell.com>
Date: Fri, 15 May 2009 01:28:03 -0600

Hi,

Here's the method that creates the ElementSet object and marshals it.

public void testJaxbProcessing() throws Exception, JAXBException {
        ElementSet es = new ElementSet();
        es.setType("es1");
        es.setVersion(Long.valueOf(0L));

        Element e = new Element();
        e.setName("e1");
        e.setType("e_type1");
        e.setId("1");
        Data data = new Data();

        Document anyValue = getDOMfromXML(new StringReader("<someData
xmlns=\"http://www.company.com/Product/Component/v1.0\"><data1
name=\"one\"><data2>1234</data2><data3>1234</data3></data1></someData>"));

        data.setAny(anyValue.getDocumentElement());
        e.setData(data);
        es.getElement().add(e);
        JAXBElement<ElementSet> jaxbElem = new JAXBElement<ElementSet>(
                        new QName("", ElementSet.class.getSimpleName()),
                        ElementSet.class, null, es);
        
        // MARSHALLING
         String esString = marshal(jaxbElem, ElementSet.class.getPackage().getName(), ElementSet.class.getClassLoader());
        
        System.out.println(esString);
}

Thanks,
Anand Navale.


>>> On 5/15/2009 at 11:29 AM, in message
<3399eb530905142259i405f025ds29ac1530cb25d238_at_mail.gmail.com>, Aleksei Valikov
<valikov_at_gmx.net> wrote:
> Hi,
>
>> Thanks for the response. The marshalling code is given below:
>
> It seems allright. How do you create your object?
>
> What I'd try is to build a small isolated test. Define a class which
> only contains and @XmlAnyElement property. Create a DOM element with
> an attribute and put it into that property. Marshall and see if it
> works.
>
> Bye.
> /lexi