473,322 Members | 1,620 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,322 software developers and data experts.

XML schema regular expressions question and recommended XML Schema book

Any suggestions or tips to the questions below I have been wrestling with
would be most welcome:

I have an example XSD file I have been experimenting with. Suppose a
user can select from 1 to 4 checkboxes on a web form:

Select your favorite sport(s):

(checkbox) baseball
(checkbox) football
(checkbox) soccer
(checkbox) golf

Futhermore, suppose a user selects all the above sports:
The xml generated from the program that reads the form variables would be:

<sport>baseball\n\football\n\soccer\n\golf</sport>

Questions:

1. what is the most effective schema statement to handle the
possiblity of the user selecting either baseball or baseball and football
or baseball, football, soccer etc..? In other words, any permutation of
checkboxes.

I would think you would use the logical or operator (|).
I was thinking something like below, but I am getting errors such as
"Datatype error: In element 'sport': Value ........ does not match regular
expression facet ................

<xsd:simpleType name="sport">
<xsd:restriction base="xsd:string">
<xsd:pattern value="baseball\\n|\\nfootball\\n|\\nsoccer\\n|gol f"/>

2. Does anyone recommend any books that explain XML Schema Regular Expressions
with some good examples? I have read Definitive XML Schema, by Walmsley.

Thanks for any tips on the above,

Fred
Jul 20 '05 #1
1 2972


Fred Smith wrote:
Any suggestions or tips to the questions below I have been wrestling with
would be most welcome:

I have an example XSD file I have been experimenting with. Suppose a
user can select from 1 to 4 checkboxes on a web form:

Select your favorite sport(s):

(checkbox) baseball
(checkbox) football
(checkbox) soccer
(checkbox) golf

Futhermore, suppose a user selects all the above sports:
The xml generated from the program that reads the form variables would be:

<sport>baseball\n\football\n\soccer\n\golf</sport>

Questions:

1. what is the most effective schema statement to handle the
possiblity of the user selecting either baseball or baseball and football
or baseball, football, soccer etc..? In other words, any permutation of
checkboxes.

I would think you would use the logical or operator (|).
I was thinking something like below, but I am getting errors such as
"Datatype error: In element 'sport': Value ........ does not match regular
expression facet ................

<xsd:simpleType name="sport">
<xsd:restriction base="xsd:string">
<xsd:pattern value="baseball\\n|\\nfootball\\n|\\nsoccer\\n|gol f"/>


If there are certain fixed values possible a list of an enumerated type
could help:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element ref="sport" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:simpleType name="sport">
<xs:restriction base="xs:string">
<xs:enumeration value="baseball" />
<xs:enumeration value="football" />
<xs:enumeration value="soccer" />
<xs:enumeration value="golf" />
</xs:restriction>
</xs:simpleType>

<xs:element name="sport">
<xs:simpleType>
<xs:list itemType="sport" />
</xs:simpleType>
</xs:element>

</xs:schema>

That allows values like

<?xml version="1.0" encoding="UTF-8"?>
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="test20040205Xsd.xml ">
<sport>baseball football soccer golf</sport>
<sport>baseball
football
soccer
golf
</sport>
<sport>soccer football</sport>
</root>

meaning the order is not restricted to what you have.
If you want to use a regular expression to restrict the type I think the
following helps:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element ref="sport" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:element name="sport">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern
value="(baseball\s*)?(football\s*)?(soccer\s*)?(go lf)?" />
</xs:restriction>
</xs:simpleType>
</xs:element>

</xs:schema>

which restricts the content of a <sport> element to being zero or one
occurrence of baseball plus some whitespace and zero or one occurence of
football plus some whitespace and zero or one occurence of soccer plus
some whitespace plus zero or one occurence of golf.
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2

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

Similar topics

8
by: Michael McGarry | last post by:
Hi, I am horrible with Regular Expressions, can anyone recommend a book on it? Also I am trying to parse the following string to extract the number after load average. ".... load average:...
1
by: Don Adams | last post by:
I don't think what I want to do with maxInclusive is possible, but I thought I'd ask others what they thought. As an example, here is some very simple XML: <birthday_cake>...
8
by: UndoMiel | last post by:
Hi, I am looking for a way to validate IP addresses using XML Schemas. The following is what i used: <xsd:simpleType name="IPType"> <xsd:restriction base="xsd:string"> <xsd:pattern...
7
by: Patient Guy | last post by:
Coding patterns for regular expressions is completely unintuitive, as far as I can see. I have been trying to write script that produces an array of attribute components within an HTML element. ...
3
by: a | last post by:
I'm a newbie needing to use some Regular Expressions in PHP. Can I safely use the results of my tests using 'The Regex Coach' (http://www.weitz.de/regex-coach/index.html) Are the Regular...
20
by: Geoff Hill | last post by:
What's the way to go about learning Python's regular expressions? I feel like such an idiot - being so strong in a programming language but knowing nothing about RE.
10
by: Thomas Dybdahl Ahle | last post by:
Hi, I'm writing a program with a large data stream to which modules can connect using regular expressions. Now I'd like to not have to test all expressions every time I get a line, as most of...
4
by: syed.akhlaq | last post by:
Hi, Does anyone know how can I validate XPath expressions using xsd schema? Thanks
12
by: FAQEditor | last post by:
Anybody have any URL's to tutorials and/or references for Regular Expressions? The four I have so far are: http://docs.sun.com/source/816-6408-10/regexp.htm...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.