JAXB generated XSD validation error "Unique Particle Attribution"

Viewed 340

I have a JAXB class, which has an element coming from another namespace. I would like to have an ANY element as well, which collects all the elements not described in the JAXB class. So I added a List<Object> annotated with the @XmlAnyElement.

I have generated an XSD from the JAXB class, but when I am validating I am getting an error: "cos-nonambig: "nb":b and WC[##other:""] (or elements from their substitution group) violate "Unique Particle Attribution". During validation against this schema, ambiguity would be created for those two particles."

The JAXB class

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType
public class Foo {

  @XmlElement
  String a;

  @XmlElement(namespace="nb")
  Bar b;

  @XmlAnyElement
  List<Object> other;
}

The XSD generated by JAXB

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" xmlns:ns1="nb" xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xs:import namespace="nb" schemaLocation="schema1.xsd"/>

  <xs:complexType name="foo">
    <xs:sequence>
      <xs:element name="a" type="xs:string" minOccurs="0"/>
      <xs:element ref="ns1:b" minOccurs="0"/>
      <xs:any processContents="skip" namespace="##other" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="bar">
    <xs:sequence>
      <xs:element name="bid" type="xs:string" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>
</xs:schema>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" targetNamespace="nb" xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xs:import schemaLocation="schema2.xsd"/>

  <xs:element name="b" type="bar"/>
</xs:schema>

How should I add the XmlAnyElement to pass the validation?

0 Answers
Related