Link to home
Start Free TrialLog in
Avatar of chenwei
chenwei

asked on

A question about XML enum to java enum

My XSD-schema looks as follow:

[code]
...
      <!-- Person -->
      <xs:complexType name="Person">
            <xs:sequence>
                       ...
                  <xs:element name="titel" type="tns:Titel" minOccurs="0" />
                       ...
            </xs:sequence>
      </xs:complexType>
...
      <!-- Titel -->
      <xs:simpleType name="Titel">
            <xs:restriction base="xs:string">
                  <xs:enumeration value="" />
                  <xs:enumeration value="Dr." />
                  <xs:enumeration value="Dr.Dr." />
                  <xs:enumeration value="Prof." />
                  <xs:enumeration value="Prof.Dr." />
            </xs:restriction>
      </xs:simpleType>
[/code]

But as I complie the XSD-Schema to java.enum, it failed. I don't know what's wrong.
Avatar of chenwei
chenwei

ASKER

But if I take out the '.' as follow, it is ok. Why?

     <!-- Titel -->
      <xs:simpleType name="Titel">
            <xs:restriction base="xs:string">
                  <xs:enumeration value="" />
                  <xs:enumeration value="Dr" />
                  <xs:enumeration value="DrDr" />
                  <xs:enumeration value="Prof" />
                  <xs:enumeration value="ProfDr" />
            </xs:restriction>
      </xs:simpleType>
Which compiler are you using?
What is your target version of Java?  
Your original Version of code works fine using Apache XMLBeans. However, if your xsd compiler was actually trying to map enumerations to Java 5 Enums, then you can't have periods in the names. as that would break the Java 5 naming conventions for type/class names.

Avatar of chenwei

ASKER

I use the Jaxb and the target is Java 5. Maybe this is the problem?
ASKER CERTIFIED SOLUTION
Avatar of MrMarshall
MrMarshall

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of chenwei

ASKER

It's quite stranged. I run my program at home's computer and it works. ut when I run the program at office's computer it failed.

Anyway many thanks.