473,813 Members | 3,529 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

W3C schema 'if..then' for attributes

I should like to allow/disallow values for an attribute based on the
value of another attribute e.g if I have a document
<character name="snow white" sex="female" hatcolour=""/>
<character name="doc" sex="male" hatcolour="brow n"/>
then this is valid. however

<character name="snow white" sex="female" hatcolour="gree n"/>

should be invalid. (in my story, female characters don't wear hats).

so I should like a schema which will allow hat colours green|brown|red
etc if the sex = 'male' but only allow the empty string for the hat
colour if the sex = 'female'.

is this possible in W3C schema?

cheers

shaun
Sep 20 '05 #1
4 1244
shaun wrote:
I should like to allow/disallow values for an attribute based on the
value of another attribute e.g if I have a document so I should like a schema which will allow hat colours green|brown|red
etc if the sex = 'male' but only allow the empty string for the hat
colour if the sex = 'female'.

is this possible in W3C schema?


No.

Soren
Sep 21 '05 #2
Soren Kuula wrote:
shaun wrote:
I should like to allow/disallow values for an attribute based on the
value of another attribute e.g if I have a document

so I should like a schema which will allow hat colours green|brown|red
etc if the sex = 'male' but only allow the empty string for the hat
colour if the sex = 'female'.

is this possible in W3C schema?


No.

Soren


So much for the "Expressive ness of XSDs".

///Peter

Sep 21 '05 #3
In article <3p************ @individual.net >,
Peter Flynn <pe********@m.s ilmaril.ie> wrote:
Soren Kuula wrote:
shaun wrote:
I should like to allow/disallow values for an attribute based on the
value of another attribute e.g if I have a document

so I should like a schema which will allow hat colours green|brown|red
etc if the sex = 'male' but only allow the empty string for the hat
colour if the sex = 'female'.

is this possible in W3C schema?


No.

Soren


So much for the "Expressive ness of XSDs".

///Peter


so I cannot declare that the same element could have one of two types,
(dodgy pseudo code follows):

choice

element =" character" type= "female character constraints"
element="charac ter" type="male character constraints"

/choice

???
Sep 22 '05 #4
shaun wrote:
In article <3p************ @individual.net >,
Peter Flynn <pe********@m.s ilmaril.ie> wrote:
Soren Kuula wrote:
shaun wrote:
I should like to allow/disallow values for an attribute based on the
value of another attribute e.g if I have a document

so I should like a schema which will allow hat colours green|brown|red
etc if the sex = 'male' but only allow the empty string for the hat
colour if the sex = 'female'.

is this possible in W3C schema?

No.

Soren


So much for the "Expressive ness of XSDs".

///Peter


so I cannot declare that the same element could have one of two types,
(dodgy pseudo code follows):

choice

element =" character" type= "female character constraints"
element="charac ter" type="male character constraints"

/choice


Correct, you can't. But you can use markup to do what you want, and
you don't need anything so complex as a Schema:

<?xml version="1.0"?>
<!DOCTYPE characters [
<!ELEMENT characters (female|male)+>
<!ELEMENT female EMPTY>
<!ATTLIST female name CDATA #REQUIRED hat CDATA #FIXED "">
<!ELEMENT male EMPTY>
<!ATTLIST male name CDATA #REQUIRED hat (green|brown|re d) #IMPLIED>
]>
<characters>
<female name="Snow White"/>
<male name="Doc" hat="brown"/>
</characters>

A validating parser will return a null value for the hat attribute for
all females.

///Peter

Sep 22 '05 #5

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

Similar topics

6
2495
by: Pieter | last post by:
I've read a lot of posts on "why relax ng is so very good" and on "why w3c xml schema should be the only schema language". I'm, however, still not clear on why I should prefer one over the other. I've made a small list of some good and bad points of both. These points don't really go into the grammar aspects of these languages, but are more about secondary aspects. The grammar aspects are different, but both are suitable for validating...
2
2286
by: wooks | last post by:
I apologise if this has been asked before, it is a bit hard to search for. I have an xml schema which defines the elements in the namespace "urn:dummy". The schema does not contain any attribute definitions/declarations. The instance XML however gets transformed at runtime with the result that a label attribute is added to each element.
3
1746
by: Rohit Sharma | last post by:
Hi all.. ..NET + MSXML platform....VB Need to build a list of all the entities and attributes to allow the user to do search...how can i do that from the schema ?? Cheers Rohit
2
9238
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" encoding="utf-8"?> <Book ID="1000000000"> <Name>XML Basic</Name> <Comments>Whatever</Comments>
6
2596
by: Martin | last post by:
Hi, I have a xml file like the one below <?xml version="1.0" encoding="utf-8"?><e1 xmlns:e1="http://tempuri.org/Source1.xsd" e1:att1="1" e1:att2="2" e1:rest="345"/> If I try to create a schema for it with Visual Studio, I get the error "Failed to create a schema for this data file because:
12
4952
by: Stefano | last post by:
Hi all, what is the correct use of the "default" attribute in XML Schema? For example: <xs:element name="myProperty" type="xs:string" default="myDefaultValue"/> What can I do with it? What is the meaning of < ....default="myDefaultValue" /> ?
2
2819
by: Chuck Bowling | last post by:
AIML Schema: http://209.168.21.76/CommunityStarterKit/Downloads/258.aspx I have a Schema (in the link above) that I've been trying to make work in VS2003 for a while now and just can't seem to get right. I didn't design the schema and to tell the truth, most of it is beyond my rudimentary understanding of XML. So far, the main problem I've run into is the simpleType below: <simpleType name="VariableName">
0
1786
by: c j anderson, mcp | last post by:
Core Question: Is there a better way to dynamically pull the allowed values of an attribute out of a dataset's schema. I have an XML file that contains a string element with two attributes, weight and color. for example, <keyword color="blue" weight="normal">And</keyword> the color and weight attributes are restricted to only certain values (color to the 16 named colors in HTML; weight to normal, bold or italic
1
19079
by: Mikus Sleiners | last post by:
I have a task to create xml document from c# code. I have example of that document should look like and also a xml schema. I wonder if i can use this xml schema somehow ? This is schema: <?xml version="1.0"?> <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
4
2977
by: ashish.sadanandan | last post by:
Hi, I'm new to XML and just started reading some documentation on W3C compliant schemas recently. The XML file I'm generating is for an embedded application and so size is of extreme importance. The information I want to save in this XML file is the attributes of the members of a structure. Now lets say there is a member variable that is an array (of length 10), so I'd want the following line in that variable's attributes:
0
9607
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
10667
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
10422
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,...
0
10139
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9222
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6897
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
5705
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3885
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3030
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.