| Author |
XSD Enum problem: POJO not generatd when numbers are used in definition, base type =xs:string
|
aravind kanganar
Ranch Hand
Joined: Nov 08, 2009
Posts: 36
|
|
Hi all,
I am trying to write an XSD- Enum type.
And then using Jaxb-xsd tool : XJCFacade I try to get the corresponding java class.
But I observe that though I 've written everything in correct syntax corresponding enum class doesn't get generated !
the type is similar to the below one:
<xs:simpleType name="EngineCapacity">
<xs:restriction base="xs:string" >
<xs:enumeration value="11a abc" />
<xs:enumeration value="a11 abc/>
</xs:restriction>
</xs:simpleType>
There were no errors reported but the class didn't get generated.
Also what I observed was that if I remove the numeric part at the start the class would get generated.
What is the secret behind this? Can any one please explain?
And is there any alternative base type I should go for?
thanks in advance
Aravind
|
 |
Ivan Krizsan
Bartender
Joined: Oct 04, 2006
Posts: 2193
|
|
Hi!
The reason for XJC not generating a class if there is an enumeration value that starts with a digit is that it is illegal for a field to start with a digit in Java.
Example:
The above type generates the following class:
If you insert a digit first in any of the names AAA, BBB or CCC in the MyCode enumeration type, there will be a syntax error.
XJC will not generate illegal Java code and will thus not generate an enumeration if one of your allowed enumeration values will result in an illegal field name.
Best wishes!
|
 |
aravind kanganar
Ranch Hand
Joined: Nov 08, 2009
Posts: 36
|
|
Hi Ivan,
Thanks for the response
But what if I need to have numbers initially?
I tried creating a simple type:
<xs:simpleType name="CustomString">
<xs:restriction base="xs:string">
<xs:pattern value="(([1-9][0-9])+)?[0-9a-zA-Z ]+"></xs:pattern>
</xs:restriction>
</xs:simpleType>
Still the tool I use (XJCFacade) complained nothing... But I found no enum class generated.
Is there any way I can get this done?
Regards,
Aravind
|
 |
Ivan Krizsan
Bartender
Joined: Oct 04, 2006
Posts: 2193
|
|
Hi!
aravind kanganar wrote:there any way I can get this done?
No, not that I know of.
Best wishes!
|
 |
aravind kanganar
Ranch Hand
Joined: Nov 08, 2009
Posts: 36
|
|
Hi Ivan,
Thanks for the help I chose to write the type with only letters finally If I get any solution I'll post it here..
-Aravind
|
 |
 |
|
|
subject: XSD Enum problem: POJO not generatd when numbers are used in definition, base type =xs:string
|
|
|