• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

xsd: how to define an element of type integer which can validate even if it is empty

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Can anyone help me solve this problem

I want to define an element to type integer
so we can do something like this ...

<xs:simpleType name="status">
<xs:annotation>
<xs ocumentation>0=CLOSED</xs ocumentation>
<xs ocumentation>1=OPEN</xs ocumentation>
</xs:annotation>
<xs:restriction base="xs:integer">
<xs:enumeration value="0"/>
<xs:enumeration value="1"/>
</xs:restriction>
</xs:simpleType>
But the problem is this will not validate an xml
<status></status>

Can anyone pl. tell me what I can use in XSD so that this gets validated
Note: I cant add any thing in xml as its getting generated automatically

Thanks in advance
 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Two ways, let me know if this meets what you need to do.

IMHO, if the base type is integer it should never allow any kind of string including blank string. So rather than trying to tweak base type xsd:integer we should use mixture of integer and string.

First solution using Union of integer and string


For integer part, I have assumed that only permissible value for status is 0 or 1. If there are other values you can change it from enumeration and use facets like min/max/Inclusive/Exclusive.

Also for String part I have put facet length=0. If you expect spaces coming use length=1 or just remove that and it should allow blank spaces. You might need to change pattern to .space.*

Other Simpler solution is to forget about Integer and just go with base type String
Like ...

I think this is more restrictive solution as you might not be able to include more values of integer in simple way. Each time you have to manually add values to the enumeration.

Hope this helps !!!

[ July 11, 2004: Message edited by: Kartik Shah ]
[ July 12, 2004: Message edited by: Kartik Shah ]
 
Bipul Kumar Singh
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Kartik...

I figured out the 1st approach myself.

The second one was new and worth to try and tweak

Thanks a lot again for response

Regds,
Bipul
 
reply
    Bookmark Topic Watch Topic
  • New Topic