Hi,
I think I may have found a bug in the RI. I'm not sure if this is already known, but I searched the archives and came up with nothing. It involves a repeating choice element with elements having attributes only:
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="
http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xsd:complexType name="DataPointer">
<xsd:sequence>
<xsd:element name="type" type="xsd:string"/>
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element name="categoryRef" type="CategoryRef"/>
<xsd:element name="fieldRef" type="FieldRef"/>
</xsd:choice>
</xsd:sequence>
<xsd:attribute name="id" type="xsd:int" use="required"/>
</xsd:complexType>
<xsd:complexType name="FieldRef">
<xsd:attribute name="id" type="xsd:int" use="required"/>
</xsd:complexType>
<xsd:complexType name="CategoryRef">
<xsd:attribute name="id" type="xsd:int" use="required"/>
</xsd:complexType>
<xsd:element name="pointer" type="DataPointer"/>
</xsd:schema>
This schema is legal and compiles fine. However, when I run the following code on it:
ObjectFactory factory = new ObjectFactory();
DataPointer pointer = factory.createPointer();
pointer.setId( -1 );
pointer.setType( "" );
List pathRef = pointer.getCategoryRefOrFieldRef();
for( int i = 0; i < 3; i++ )
{
FieldRef fieldRef = factory.createFieldRef();
fieldRef.setId( i );
pathRef.add( fieldRef );
}
JAXBContext jc = JAXBContext.newInstance( "datapointer" );
Marshaller m = jc.createMarshaller();
m.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE );
m.marshal( pointer, System.out );
This is produced:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<pointer id="-1" id="0" id="1" id="2">
<type></type>
</pointer>
I can only guess this is a bug since the XML generated is obviously invalid. Are there any known workarounds?
Thanks,
Craig