highsource / jaxb2-basics

Useful plugins and tools for JAXB2.
BSD 2-Clause "Simplified" License
109 stars 54 forks source link

Elements with ref attribute #83

Open rochafrancisco opened 7 years ago

rochafrancisco commented 7 years ago

Hi,

Assuming the code that follows:


<!-- example complexType based on an entry from the XSD -->
<complexType name="ElementInfoType" mixed="true">
  <choice maxOccurs="unbounded">
    <element ref="Element0"/>
    <element ref="Element1"/>
    <element ref="Element2"/>
    <any processContents="lax" namespace="##other"/>
  </choice>
  <attribute name="Id" type="ID" use="optional"/>
</complexType>

<!-- example jaxb xjb -->
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
  xmlns:simplify="http://jaxb2-commons.dev.java.net/basic/simplify"
  jaxb:extensionBindingPrefixes="xjc simplify" jaxb:version="2.1">
  <jaxb:bindings schemaLocation="schema.xsd" node="/xs:schema">
    <jaxb:bindings node="xs:complexType[@name='ElementInfoType']/xs:choice/xs:element[1]">
      <simplify:as-element-property />
    </jaxb:bindings>
  </jaxb:bindings>
</jaxb:bindings>

I am getting an error:

[ERROR] Error while parsing schema(s).Location [ jaxb.xjb{21,38}].
com.sun.istack.SAXParseException2; systemId: jaxb.xjb; lineNumber: 21; columnNumber: 38; compiler was unable to honor this as-element-property customization. It is attached to a wrong place, or its inconsistent with other bindings.

I would like to know if there is any known issue with the attribute ref or if there is something I am missing. I have already tried placing it at different locations in the path.

A similar approach works for:

<!-- example complexType based on an entry from the XSD -->

<complexType name="DataType">
  <sequence maxOccurs="unbounded">
    <choice>
      <element name="Element0" type="string"/>
      <element name="Element1" type="base64Binary"/>
      <element name="Element2" type="string"/>
      <any namespace="##other" processContents="lax"/>
    </choice>
  </sequence>
</complexType>

Note: I cannot change the xsd file.

Thank you for your time.

Kind regards, Francisco

rochafrancisco commented 7 years ago

Issue #7 mentions this problem, however, the solution suggested there is not working.