XSD w3 standard ID data type (that allows spaces)?

R

RickH

Hello,

I would like to create a user XSD data type that inherits from the w3
standard data type called ID to make sure a certain repeated element
always contains distinct values. The problem is I would like this
element to also allow spaces to be present. By default the ID data
type does not allow spaces.

How can I inherit ID and also allow the entry of spaces in the data of
a new derived data type? This is a title column where I dont want to
allow a duplicate title to ever be entered and the title is also to be
a user-friendly distinct key, so I am reluctant to use system type
keys or guids. I tried the following but my document still fails to
validate when a space is entered in the elements that are typed as
"typeTitle" below:

Schema:

<xsd:simpleType name="typeTitle">
<xsd:restriction base="xsd:ID">
<xsd:maxLength value="100"/>
<xsd:whiteSpace value="preserve"/>
</xsd:restriction>
</xsd:simpleType>

<xsd:element name="Title" type="typeTitle"/>

Test data that passes validation:

<Titles>
<Title>abc</Title>
<Title>xyz</Title>
</Titles>

Test data that passes distinctness but fails with spaces (I need a
data type that allows this doc to only be validated for distinctness):

<Titles>
<Title>Gone With The Wind</Title>
<Title>Satin Doll</Title>
</Titles>



I'm using the Microsoft XML DOM.

Maybe there is some other w3 data type I am not aware of maybe called
"distinctData" or something that will allow all characters and only
implement the distinctness rule of ID's?

Thanks for any help
Rick
 
R

roy axenov

How can I inherit ID and also allow the entry of spaces
in the data of a new derived data type?

I believe you can't.
Maybe there is some other w3 data type I am not aware of
maybe called "distinctData"

No, but see:

http://www.perlmonks.org/index.pl?node_id=542341
or something that will allow all characters and only
implement the distinctness rule of ID's?

Sort of. See W3C's XML Schema Primer, 5.1.

(I think some selfless hero should step forward and start
a ctx FAQ. This one's certainly a contender for the top
spot in the XML Schema section.)
 
R

RickH

Hello,

I would like to create a user XSD data type that inherits from the w3
standard data type called ID to make sure a certain repeated element
always contains distinct values. The problem is I would like this
element to also allow spaces to be present. By default the ID data
type does not allow spaces.

How can I inherit ID and also allow the entry of spaces in the data of
a new derived data type? This is a title column where I dont want to
allow a duplicate title to ever be entered and the title is also to be
a user-friendly distinct key, so I am reluctant to use system type
keys or guids. I tried the following but my document still fails to
validate when a space is entered in the elements that are typed as
"typeTitle" below:

Schema:

<xsd:simpleType name="typeTitle">
<xsd:restriction base="xsd:ID">
<xsd:maxLength value="100"/>
<xsd:whiteSpace value="preserve"/>
</xsd:restriction>
</xsd:simpleType>

<xsd:element name="Title" type="typeTitle"/>

Test data that passes validation:

<Titles>
<Title>abc</Title>
<Title>xyz</Title>
</Titles>

Test data that passes distinctness but fails with spaces (I need a
data type that allows this doc to only be validated for distinctness):

<Titles>
<Title>Gone With The Wind</Title>
<Title>Satin Doll</Title>
</Titles>

I'm using the Microsoft XML DOM.

Maybe there is some other w3 data type I am not aware of maybe called
"distinctData" or something that will allow all characters and only
implement the distinctness rule of ID's?

Thanks for any help
Rick

Oops, nevermind, I just found the w3 chapter on Identity-constraint
Definition and use of the :key element. That sounds like what I need,
correct? As long as my constraint xPath query returns either 0 or 1
row for the data match, then the restriction knows it's distinct.

If you still want to answer this, thats ok, but I think I can figure
it out.
 
J

Joseph Kesselman

RickH said:
I would like to create a user XSD data type that inherits from the w3
standard data type called ID to make sure a certain repeated element
always contains distinct values.

Wrong solution. If what you want is unique values, you can say exactly
that in Schema by using (surprisingly enough) the "unique" constraint.
If you want a set of values which are unique at point of assertion but
can be referred to (like IDs, but separate from the official ID space),
use the "key" and "keyref" constraints.

http://www.w3.org/TR/2004/REC-xmlschema-1-20041028/#declare-key
 
J

Joseph Kesselman

roy said:
(I think some selfless hero should step forward and start
a ctx FAQ.

Well, there are a lot of other XML FAQs out there, so the first thing to
do would be to point to those... but, yeah, that thought has occurred to
me. Certainly that's how the XSL FAQ was assembled.

The most elegant solution (least effort for any one person, though
conversely least credit to any one person) would be to find a Wiki
somewhere that's willing to host this FAQ, and build it up collaboratively.
 
R

roy axenov

Well, there are a lot of other XML FAQs out there, so the
first thing to do would be to point to those...

Indeed, that's a very important part of any newsgroup FAQ's
job description.
Certainly that's how the XSL FAQ was assembled.

And that's its biggest problem, actually... I mean, it's an
excellent reading for anyone willing to improve their
overall XSL-fu, but I would expect neophytes to get lost in
its depths long before finding actual answers to basic
questions (short, concise and to the point).
The most elegant solution (least effort for any one
person, though conversely least credit to any one person)
would be to find a Wiki somewhere that's willing to host
this FAQ, and build it up collaboratively.

I suppose we'll need a slightly-less-selfless hero to step
forward with a Wiki hosting. Actually, collaboration of the
group regulars seems to be the only solution anyway, since
I don't believe there's any one person sufficiently
conversant in all aspects of XML technologies--even if we
consider only the more important aspects, without delving
into the grisly details of implementation-specific stuff
and useful-but-somewhat-esoteric tools. (And if such a
person exists, he/she is probably too busy with his/her
demigodly pursuits to spare the time for maintaining a
newsgroup FAQ.)
 
R

RickH

Well, there are a lot of other XML FAQs out there, so the first thing to
do would be to point to those... but, yeah, that thought has occurred to
me. Certainly that's how the XSL FAQ was assembled.

The most elegant solution (least effort for any one person, though
conversely least credit to any one person) would be to find a Wiki
somewhere that's willing to host this FAQ, and build it up collaboratively.

I used the <xsd:unique> at collection level to inspect the children
for distinctness:

Here is my final solution that works in case anyone is interested, my
code is spread over several include files so I'll just paste each with
the file name in upper case preceeding that files contents: (3 files
follow, the test file is last and makes ref to the songs.xsd file, and
songs.xsd includes by ref my global types)

SONGS.XSD
------------------------

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:include schemaLocation="types.xsd" />
<xs:element name="Songs" type="typeSongs">
<xs:unique name="keyTitle">
<xs:selector xpath="Song"/>
<xs:field xpath="Title"/>
</xs:unique>
</xs:element>
</xs:schema>



TYPES.XSD
------------------------

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">

<!-- Simple Types -->

<xs:simpleType name="typeTitle">
<xs:restriction base="xs:string">
<xs:maxLength value="100"/>
</xs:restriction>
</xs:simpleType>

<xs:simpleType name="typeFilePath">
<xs:restriction base="xs:string">
<xs:whiteSpace value="preserve"/>
</xs:restriction>
</xs:simpleType>

<xs:simpleType name="typeFitPage">
<xs:restriction base="xs:string">
<xs:enumeration value="HEIGHT"/>
<xs:enumeration value="WIDTH"/>
<xs:enumeration value="Height"/>
<xs:enumeration value="Width"/>
<xs:enumeration value="height"/>
<xs:enumeration value="width"/>
</xs:restriction>
</xs:simpleType>

<xs:simpleType name="typeRating">
<xs:restriction base="xs:integer">
<xs:minInclusive value="1"/>
<xs:maxInclusive value="5"/>
</xs:restriction>
</xs:simpleType>

<xs:simpleType name="typeVolume">
<xs:restriction base="xs:integer">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="100"/>
</xs:restriction>
</xs:simpleType>

<xs:simpleType name="typeBalance">
<xs:restriction base="xs:integer">
<xs:minInclusive value="-100"/>
<xs:maxInclusive value="100"/>
</xs:restriction>
</xs:simpleType>

<xs:simpleType name="typeTimeSignature">
<xs:restriction base="xs:string">
<xs:pattern value="[123456789][/][123456789]"/>
</xs:restriction>
</xs:simpleType>

<xs:simpleType name="typeKey">
<xs:restriction base="xs:string">
<xs:enumeration value="A Maj"/>
<xs:enumeration value="A# Maj"/>
<xs:enumeration value="Bb Maj"/>
<xs:enumeration value="B Maj"/>
<xs:enumeration value="B# Maj"/>
<xs:enumeration value="C Maj"/>
<xs:enumeration value="C# Maj"/>
<xs:enumeration value="Db Maj"/>
<xs:enumeration value="D Maj"/>
<xs:enumeration value="D# Maj"/>
<xs:enumeration value="Eb Maj"/>
<xs:enumeration value="E Maj"/>
<xs:enumeration value="E# Maj"/>
<xs:enumeration value="F Maj"/>
<xs:enumeration value="F# Maj"/>
<xs:enumeration value="Gb Maj"/>
<xs:enumeration value="G Maj"/>
<xs:enumeration value="G# Maj"/>
<xs:enumeration value="Ab Maj"/>
<xs:enumeration value="A Min"/>
<xs:enumeration value="A# Min"/>
<xs:enumeration value="Bb Min"/>
<xs:enumeration value="B Min"/>
<xs:enumeration value="B# Min"/>
<xs:enumeration value="C Min"/>
<xs:enumeration value="C# Min"/>
<xs:enumeration value="Db Min"/>
<xs:enumeration value="D Min"/>
<xs:enumeration value="D# Min"/>
<xs:enumeration value="Eb Min"/>
<xs:enumeration value="E Min"/>
<xs:enumeration value="E# Min"/>
<xs:enumeration value="F Min"/>
<xs:enumeration value="F# Min"/>
<xs:enumeration value="Gb Min"/>
<xs:enumeration value="G Min"/>
<xs:enumeration value="G# Min"/>
<xs:enumeration value="Ab Min"/>
</xs:restriction>
</xs:simpleType>

<xs:simpleType name="typeMessage">
<xs:restriction base="xs:string">
<xs:whiteSpace value="preserve"/>
<xs:maxLength value="500"/>
</xs:restriction>
</xs:simpleType>

<!-- Complex (1 level) Types -->

<xs:complexType name="typeSongData">
<xs:sequence>
<xs:element name="Title" type="typeTitle"/>
<xs:element name="Audio" type="typeFilePath"/>
<xs:element name="Sheet" type="typeFilePath"/>
<xs:element name="Page" type="xs:positiveInteger" minOccurs="0"
maxOccurs="1"/>
<xs:element name="Composers" type="xs:string" minOccurs="0"
maxOccurs="1"/>
<xs:element name="FitPage" type="typeFitPage" minOccurs="0"
maxOccurs="1"/>
<xs:element name="StartAt" type="xs:time" minOccurs="0"
maxOccurs="1"/>
<xs:element name="Keywords" type="xs:string" minOccurs="0"
maxOccurs="1"/>
<xs:element name="GeneralRating" type="typeRating" minOccurs="0"
maxOccurs="1"/>
<xs:element name="DifficultyRating" type="typeRating" minOccurs="0"
maxOccurs="1"/>
<xs:element name="RehearsalRating" type="typeRating" minOccurs="0"
maxOccurs="1"/>
<xs:element name="TimeSignature" type="typeTimeSignature"
minOccurs="0" maxOccurs="1"/>
<xs:element name="Key" type="typeKey" minOccurs="0" maxOccurs="1"/>
<xs:element name="TempoBPM" type="xs:positiveInteger" minOccurs="0"
maxOccurs="1"/>
<xs:element name="Volume" type="typeVolume" minOccurs="0"
maxOccurs="1"/>
<xs:element name="Balance" type="typeBalance" minOccurs="0"
maxOccurs="1"/>
</xs:sequence>
</xs:complexType>

<!-- Complex (2 level) Types -->

<xs:complexType name="typeSong">
<xs:sequence>
<xs:element name="Song" type="typeSongData"/>
</xs:sequence>
</xs:complexType>

<!-- Complex Collection Types -->

<xs:complexType name="typeSongs">
<xs:sequence>
<xs:element name="Song" type="typeSongData" minOccurs="0"
maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>

</xs:schema>


SONGS.XML (this test file will fail with a duplicate Title)
------------------------------------------------------------------------------------

<Songs xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="Schema/songs.xsd">
<Song>
<Title>One</Title>
<Audio>hw1.wav</Audio>
<Sheet>testcutepdf.pdf</Sheet>
<Page>2</Page>
<Composers>Jobim</Composers>
<Keywords>Latin,Cuban,Slow</Keywords>
<GeneralRating>3</GeneralRating>
<DifficultyRating>3</DifficultyRating>
<RehearsalRating>3</RehearsalRating>
</Song>
<Song>
<Title>a song</Title>
<Audio>hw1.wav</Audio>
<Sheet>testcutepdf.pdf</Sheet>
<Page>2</Page>
<FitPage>width</FitPage>
</Song>
<Song>
<Title>Route 66 Hal Leonard Best of Swing 13</Title>
<Audio>hw1.wav</Audio>
<Sheet>testcutepdf.pdf</Sheet>
<Page>2</Page>
<FitPage>width</FitPage>
</Song>
<Song>
<Title>the song</Title>
<Audio>hw1.wav</Audio>
<Sheet>testcutepdf.pdf</Sheet>
<Page>2</Page>
<FitPage>width</FitPage>
</Song>
<Song>
<Title>Two</Title>
<Audio>Route 66 Hal Leonard Best of Swing 13.wma</Audio>
<Sheet>IACReference.pdf</Sheet>
<Page>1</Page>
<FitPage>height</FitPage>
<StartAt>00:00:03</StartAt>
<Keywords>swing,road</Keywords>
<GeneralRating>4</GeneralRating>
<DifficultyRating>4</DifficultyRating>
<RehearsalRating>4</RehearsalRating>
<TimeSignature>4/4</TimeSignature>
<Key>F Maj</Key>
<TempoBPM>120</TempoBPM>
<Volume>100</Volume>
<Balance>0</Balance>
</Song>
<Song>
<Title>Three</Title>
<Audio>hw2.wav</Audio>
<Sheet>IACReference.pdf</Sheet>
<Page>11</Page>
</Song>
<Song>
<Title>Four</Title>
<Audio>hw1xxxx.wav</Audio>
<Sheet>testcutepdfXXXX.pdf</Sheet>
<Page>1</Page>
</Song>
<Song>
<Title>Five</Title>
<Audio>hw1.wav</Audio>
<Sheet>testcutepdf.pdf</Sheet>
<Page>1</Page>
</Song>
<Song>
<Title>Six</Title>
<Audio>hw2.wav</Audio>
<Sheet>nabble_javascript_error.pdf</Sheet>
<Page>1</Page>
</Song>
<Song>
<Title>a song</Title>
<Audio>hw1.wav</Audio>
<Sheet>testcutepdf.pdf</Sheet>
<Page>2</Page>
<FitPage>width</FitPage>
</Song>
</Songs>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top