users@jaxb.java.net

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

From: Aleksei Valikov <valikov_at_gmx.net>
Date: Thu, 14 May 2009 12:47:33 +0200

Hi,

> I am using Java 5 and JAXB RI 2.1.7 for my project and XJC utility coming with it for generating java code mapping to the XML schema. I m facing problems marshaling an object which has one of its fields mapping to <xs:any> type. Specifically, the problem arises whenever the XML DOM element mapping the <xs:any> element includes attributes. For the schema mentioned below:
> SCHEMA:
> <!-- --------------------------------------------------------------------------- -->
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
> xmlns="http://www.company.com/Product/Component/v1.0"
> targetNamespace="http://www.company.com/Product/Component/v1.0"
> elementFormDefault="qualified" attributeFormDefault="unqualified">
> <xs:complexType name="Element">
> <xs:sequence>
> <xs:element name="Name" type="xs:string" minOccurs="0" />
> <xs:element name="Description" type="xs:string" minOccurs="0" />
> <xs:element name="Data" minOccurs="0">
> <xs:complexType>
> <xs:sequence>
> <xs:any/>
> </xs:sequence>
> </xs:complexType>
> </xs:element>
> </xs:sequence>
> <xs:attribute name="Type" type="xs:string" />
> <xs:attribute name="Id" type="xs:string" use="required" />
> </xs:complexType>
> <xs:complexType name="ElementSet">
> <xs:sequence>
> <xs:element name="Element" type="Element" minOccurs="0" maxOccurs="unbounded"/>
> <xs:element name="ElementSetAny" minOccurs="0">
> <xs:complexType>
> <xs:sequence>
> <xs:any namespace="##other" minOccurs="0" maxOccurs="unbounded"/>
> </xs:sequence>
> </xs:complexType>
> </xs:element>
> </xs:sequence>
> <xs:attribute name="Type" type="xs:string"/>
> <xs:attribute name="Version" type="xs:long" use="optional"/>
> </xs:complexType>
> </xs:schema> <!-- schema ends here -->
> <!-- --------------------------------------------------------------------------- -->
>
> marshaling produces the following XML data which looks malformed:
>
> <!-- --------------------------------------------------------------------------- -->
> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
> <ElementSet Version="0" Type="es1" xmlns:ns2="http://www.company.com/Product/Component/v1.0">
> <ns2:Element Id="1" Type="e_type1">
> <ns2:Name>e1</ns2:Name>
> <ns2:Data>
> <ns2:someData xmlns="http://www.company.com/Product/Component/v1.0">
> <data1 name="one" xmlns:ns4="http://www.company.com/Product/Component/v1.0" xmlns="">
> <ns4:data2>1234</ns4:data2>
> <ns4:data3>1234</ns4:data3>
> </data1>
> </ns2:someData>
> </Data>
> </Element>
> </ElementSet>
> <!-- --------------------------------------------------------------------------- -->

This is very surprizing. Element prefixes got stripped in the resulting XML.
Could you post the marshalling code?

Bye.
/lexi