473,386 Members | 1,924 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

XSD restrictions - both string and numerical

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 -->

Feb 12 '08 #1
4 2346
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/
Feb 12 '08 #2
On 12 Feb, 11:33, voorth <voo...@xs4all.nlwrote:
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
Feb 12 '08 #3
On 12 Feb, 12:41, use...@tech-know-ware.com wrote:
On 12 Feb, 11:33, voorth <voo...@xs4all.nlwrote:
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

Feb 12 '08 #4
Thanks, guys, that was just what I was looking for.
Feb 12 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: dont bother | last post by:
Hey, I have these attributes: index which is a numerical value value vector which is a numerical float value and I want to concatenate like this:
108
by: Bryan Olson | last post by:
The Python slice type has one method 'indices', and reportedly: This method takes a single integer argument /length/ and computes information about the extended slice that the slice object would...
2
by: Shailendra Batham | last post by:
Hello Gurus, I want to put some restrictions on my attribute tag in my XML Schema, anyone out there have any idea how to do that. here is my XML and the XML Schema <?xml version="1.0"...
5
by: Marc Scheuner [MVP ADSI] | last post by:
Folks, I need to try and make sure that a given string is a valid numerical value (not just int, or int32 - it could be float, decimal, what have you). VB.NET has a neat "IsNumeric" function -...
3
by: Raed Sawalha | last post by:
I have the following letters; string letters = "a;b;c....to z"; the I need to replace the incoming string which containing letters above with integer 1 i did following for(int...
2
by: farah727rash | last post by:
Hi all, I am trying to find the numerical value of a string that stores a two digit number. I have found the numerical value of a char as: char character; cin >> character; int number =...
8
by: farah727rash | last post by:
Hi all, I am trying to find the numerical value of a string that stores a two digit number. I have found the numerical value of a char as: char character; cin >character; int number =...
6
by: Mark Chimes | last post by:
Hi All, I need to search thru some strings and discard them if they canot be converted to a decimal or interger value. What is the best way to do this? cheers, Mark Chimes
1
by: Paul van Brouwershaven | last post by:
Hi All, I'm struggling with the WDSL restrictions in PHP/SOAP for a while know. I would like to create some simple restrictions in my WDSL file. The script are running both on the same server...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.