473,811 Members | 2,685 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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\s occer\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:simpleTy pe name="sport">
<xsd:restrictio n base="xsd:strin g">
<xsd:pattern value="baseball \\n|\\nfootball \\n|\\nsoccer\\ n|golf"/>

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 2999


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\s occer\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:simpleTy pe name="sport">
<xsd:restrictio n base="xsd:strin g">
<xsd:pattern value="baseball \\n|\\nfootball \\n|\\nsoccer\\ n|golf"/>


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="unbo unded" />
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:simpleTyp e name="sport">
<xs:restricti on base="xs:string ">
<xs:enumerati on value="baseball " />
<xs:enumerati on value="football " />
<xs:enumerati on value="soccer" />
<xs:enumerati on value="golf" />
</xs:restriction>
</xs:simpleType>

<xs:element name="sport">
<xs:simpleTyp e>
<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:noNamespace SchemaLocation= "test20040205Xs d.xml">
<sport>baseba ll football soccer golf</sport>
<sport>baseba ll
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="unbo unded" />
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:element name="sport">
<xs:simpleTyp e>
<xs:restricti on base="xs:string ">
<xs:pattern
value="(basebal l\s*)?(football \s*)?(soccer\s* )?(golf)?" />
</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
2433
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: 0.04, 0.02, 0.01" how can I extract this number with RE or otherwise?
1
1819
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> <max_pieces>8</max_pieces> <serving name="Joe"> <pieces>2</pieces> </serving> <serving name="Jane">
8
13543
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 value="((? | 1 | 2 | 25)\.){3} (? | 1 |
7
2192
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. Consider the example of the HTML element TABLE with the following attributes producing sufficient complexity within the element: <table id="machines" class="noborders inred" style="margin:2em 4em;background-color:#ddd;">
3
3028
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 Expressions used in Perl identical to the Regular Expressions in PHP?
20
3427
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
1883
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 the time, one of them having a match means none of the others can have so. But ofcource there are also cases where a regular expression can "contain" another expression, like in: "^strange line (\w+) and (\w+)$" and "^strange line (\w+) (?:.*?)$"...
4
9133
by: syed.akhlaq | last post by:
Hi, Does anyone know how can I validate XPath expressions using xsd schema? Thanks
12
2494
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 http://en.wikipedia.org/wiki/Regular_expression http://www.regular-expressions.info/javascript.html http://www.webreference.com/js/column5/
0
9727
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9605
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10647
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10398
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7669
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6889
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5554
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4339
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3017
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.