users@jaxb.java.net

Q: Element and Attribute with the same identifier

From: Herve Bitteur <Herve.Bitteur_at_Sun.COM>
Date: Fri, 30 Mar 2007 12:05:35 +0200

Bonjour,

I'm using xjc on an XML schema to get the corresponding Java classes.
The problem is that in the definition of a given element, I have both:

    * a (sub)element named 'foo' in a sequence
    * and an attribute also named 'foo';

Running xjc, I get an error saying: Property "Foo" is already defined.
Is this an xjc bug? For me, the file Foo.java should be created for the
(sub)element only, the attribute is just a local string.
Is there any workaround, perhaps by using some customizing instruction
(which I'm not at all familiar with)?

Thanks for your help!
Bye
/Hervé

For completeness, here are the lines from the actual example (the
problem arises for both 'segno' and for 'coda'):

 <xs:element name='barline'>
  <xs:complexType>
   <xs:sequence>
     <xs:element ref='bar-style' minOccurs='0'/>
     <xs:sequence>
       <xs:element ref='footnote' minOccurs='0'/>
       <xs:element ref='level' minOccurs='0'/>
     </xs:sequence>
     <xs:element ref='wavy-line' minOccurs='0'/>
     <xs:element ref='segno' minOccurs='0'/>
     <xs:element ref='coda' minOccurs='0'/>
     <xs:element ref='fermata' minOccurs='0' maxOccurs='unbounded'/>
     <xs:element ref='ending' minOccurs='0'/>
     <xs:element ref='repeat' minOccurs='0'/>
   </xs:sequence>
  <xs:attribute name='location' default='right'>
   <xs:simpleType>
    <xs:restriction base='xs:string'>
     <xs:enumeration value='right'/>
     <xs:enumeration value='left'/>
     <xs:enumeration value='middle'/>
    </xs:restriction>
   </xs:simpleType>
  </xs:attribute>
  <xs:attribute name='segno'/>
  <xs:attribute name='coda'/>
  <xs:attribute name='divisions'/>
  </xs:complexType>
 </xs:element>


-- 
<http://www.sun.com> 	*Hervé Bitteur*
Software Program Manager
*Sun Microsystems, Inc.*
13, Avenue Morane Saulnier
78142 Vélizy Cedex FRANCE
Phone +33 1 34 03 01 12
Mobile +33 6 86 49 04 14
Fax     +33 1 34 03 07 56
Email   herve.bitteur_at_sun.com
Skype hbitteur <skype:hbitteur?call>