users@jaxb.java.net

Handling repeating element names inside a complex type

From: Kris Easter <Kris.Easter_at_colorado.edu>
Date: Tue, 03 Aug 2010 13:41:52 -0600

I'm trying to parse a XSD with JAXB that has elements with the same name
inside sequences inside a complex type. I posted a variant on the
problem on the Metro web forum using wsimport but I think I've got it
narrowed down to a JAXB question so I thought I'd ask about it here.
Hopefully this won't be considered a cross-post.

With this:

xjc TestRepeatingSchema.xsd

I get this:

[ERROR] Element "{http://www.example.org/TestRepeatingSchema}PSCAMA"
shows up in more than one properties.

I've tried adding in line annotations like:

<xsd:element minOccurs="0" name="PSCAMA" type="xsd:string">
  <xsd:annotation>
    <xsd:appinfo>
      <jxb:property name="PSCAMA1" />
    </xsd:appinfo>
  </xsd:annotation>
 </xsd:element>

And a similar approach with a .xjb file. The inline annotations result
in:

[ERROR] compiler was unable to honor this property customization. It is
attached to a wrong place, or its inconsistent with other bindings.

The .xjb file throws an xpath violation:

[ERROR] XPath evaluation of ".//xs:element[@name='PSCAMA']" results in
too many (2) target nodes

Can someone tell me what I'm doing wrong and how to get JAXB to parse
this correctly? I believe it's a "valid" schema but if it's not I can
at least take that back to the developer of the webservice and see if
they'll change the schema.

A sample schema that shows the problem is:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
        jxb:version="2.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        targetNamespace="http://www.example.org/TestRepeatingSchema"
xmlns="http://www.example.org/TestRepeatingSchema"
        elementFormDefault="qualified">

<xsd:complexType name="SCC_SM_SERVICEMsgDataRecord_TypeShape">

 <xsd:sequence>

  <xsd:sequence minOccurs="0" maxOccurs="unbounded">
    <xsd:element name="SCC_SM_RULE_VW" type="xsd:string" />
    <xsd:element minOccurs="0" name="PSCAMA" type="xsd:string"/>
  </xsd:sequence>

  <xsd:sequence minOccurs="0" maxOccurs="unbounded">
    <xsd:element name="SCC_SM_PRSN_VW" type="xsd:string" />
    <xsd:element minOccurs="0" name="PSCAMA" type="xsd:string">

    <!--<xsd:annotation>
          <xsd:appinfo>
            <jxb:property name="PSCAMA1" />
          </xsd:appinfo>
        </xsd:annotation>
    -->
    </xsd:element>

  </xsd:sequence>
 </xsd:sequence>
</xsd:complexType>

</xsd:schema>

Thanks for any help you can offer.

Kris