Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XSD restrictions - both string and numerical

Reply
Thread Tools

XSD restrictions - both string and numerical

 
 
voorth
Guest
Posts: n/a
 
      02-12-2008
I was wondering if it is possible to define an restricted attribute
such that the following forms are both valid:

<myElement value="hi"/> <!-- value should be "hi" or "lo" -->
<myElement value="100"/><!-- value should be between 50-150 -->

 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      02-12-2008
voorth wrote:
> I was wondering if it is possible to define an restricted attribute
> such that the following forms are both valid:
>
> <myElement value="hi"/> <!-- value should be "hi" or "lo" -->
> <myElement value="100"/><!-- value should be between 50-150 -->


You can define a union type of two simple types:

<xs:attribute name="value">
<xs:simpleType>
<xs:union>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="hi"/>
<xs:enumeration value="lo"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType>
<xs:restriction base="xs:int">
<xs:minInclusive value="50"/>
<xs:maxInclusive value="100"/>
</xs:restriction>
</xs:simpleType>
</xs:union>
</xs:simpleType>
</xs:attribute>

See section "2.5.1.3 Union datatypes" in
<URL:http://www.w3.org/TR/xmlschema-2/#datatype-dichotomies>
--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
 
 
 
usenet@tech-know-ware.com
Guest
Posts: n/a
 
      02-12-2008
On 12 Feb, 11:33, voorth <voo...@xs4all.nl> wrote:
> I was wondering if it is possible to define an restricted attribute
> such that the following forms are both valid:
>
> <myElement value="hi"/> <!-- value should be "hi" or "lo" -->
> <myElement value="100"/><!-- value should be between 50-150 -->


You can use XML schema xs:union construct to do this. Something along
the lines of:

<xs:attribute name="value">
<xs:simpleType>
<xs:union>
<xs:simpleType>
<xs:restriction base="xs:int">
<xs:minInclusive value="50"/>
<xs:maxInclusive value="150"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="hi"/>
</xs:restriction>
</xs:simpleType>
</xs:union>
</xs:simpleType>
</xs:attribute>

Although you probably don't want the string part as restricted as
this!

HTH,

Pete Cordell
Codalogic
Visit http://www.codalogic.com/lmx/ for XML C++ data binding
 
Reply With Quote
 
usenet@tech-know-ware.com
Guest
Posts: n/a
 
      02-12-2008
On 12 Feb, 12:41, use...@tech-know-ware.com wrote:
> On 12 Feb, 11:33, voorth <voo...@xs4all.nl> wrote:
>
> > I was wondering if it is possible to define an restricted attribute
> > such that the following forms are both valid:

>
> ...
>
> Although you probably don't want the string part as restricted as
> this!


Ooops, missed the 'lo' part. See Martin's answer for that. He must
type faster than me!

HTH,

Pete Cordell
Codalogic
Visit http://www.codalogic.com/lmx/ for XML C++ data binding

 
Reply With Quote
 
voorth
Guest
Posts: n/a
 
      02-12-2008
Thanks, guys, that was just what I was looking for.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XSD restrictions/extensions Arinté XML 0 12-18-2008 03:51 PM
how to use restrictions and extensions in XSD simultanously Dmitry Kulinich XML 5 02-21-2007 10:41 AM
How to convert string to an expression in PERL or calculating numerical string rajesh Perl Misc 0 11-23-2005 01:03 PM
Restrictions in XSD TIANA XML 0 12-07-2004 09:38 PM
Difference between <import ....xsd> and <xlink:href=.....xsd> ???? Bernd Oninger XML 1 06-30-2004 08:21 AM



Advertisments