users@jaxb.java.net

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

From: Aleksei Valikov <valikov_at_gmx.net>
Date: Fri, 15 May 2009 10:55:04 +0200

Hi,

> Also including the method getDOMFromXML()....
>
> Document getDOMfromXML(Reader reader) throws Exception{
> DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
> DocumentBuilder builder = factory.newDocumentBuilder();
> InputSource is = new InputSource(reader);
> Document document = builder.parse(is);
> return document;
> }
>
> Here's the method that creates the ElementSet object and marshals it.
>
>
> public void testJaxbProcessing() throws Exception {
> 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);
> }


Your code seems to be allright.
Would you also send me the schema files? I'll try it when I have time
over the weekend.

Bye.
/lexi