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

Co-occurrence Constraints

Hi,

Eric van der Vlist's book XML Schema says that we can use xs:key to declare
co-occurrence constraints. The example he uses (boiled down a bit) is a
"book" element that must have either an "isbn" attribute or an "isbn" child
element, but not both:

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema targetNamespace="http://www.example.com"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.example.com"
elementFormDefault="qualified">

<xs:element name="book">
<xs:complexType>
<xs:sequence>
<xs:element name="isbn" type="xs:string" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="isbn" type="xs:string"/>
</xs:complexType>

<xs:key name="dummy">
<xs:selector xpath="."/>
<xs:field xpath="isbn|@isbn"/>
</xs:key>

</xs:element>

</xs:schema>

Now, if the isbn attribute (only) is present, it validates fine. But if the
isbn child (only) is present, I get the following validation error:

The identity constraint 'http://www.example.com:dummy' validation has failed
due to either a key is missing or the exsisting key has an empty node.

And if both the attribute and child are present, I get no validation error
(which is wrong).

I am using Visual Studio .NET, hence the .NET Framework version 1.0. Am I
experiencing a limitation in Microsoft's support for XML Schema, or am I
missing something? Any insights appreciated!
Eric W. Sirko
Nov 12 '05 #1
2 1768
Hi Eric,

XPath expressions like (isbn|@isbn) are not affected by default namespace
declarations. Therefore, you must assign a prefix to the target namespace
and use that prefix in the XPath expression, or it won't find the isbn
element. So, it should look like this:

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema targetNamespace="http://www.example.com"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:ex="http://www.example.com"
elementFormDefault="qualified">

<xs:element name="book">
<xs:complexType>
<xs:sequence>
<xs:element name="isbn" type="xs:string" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="isbn" type="xs:string"/>
</xs:complexType>

<xs:key name="dummy">
<xs:selector xpath="."/>
<xs:field xpath="ex:isbn|@isbn"/>
</xs:key>

</xs:element>

</xs:schema>

Hope that helps,
Priscilla
------------------------------------------------------------------
Priscilla Walmsley
Author, Definitive XML Schema / XML in Office 2003
http://www.datypic.com
------------------------------------------------------------------

"Eric W. Sirko" <es****@sw-sol.com> wrote in message
news:ed*************@TK2MSFTNGP12.phx.gbl...
Hi,

Eric van der Vlist's book XML Schema says that we can use xs:key to
declare
co-occurrence constraints. The example he uses (boiled down a bit) is a
"book" element that must have either an "isbn" attribute or an "isbn"
child
element, but not both:

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema targetNamespace="http://www.example.com"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.example.com"
elementFormDefault="qualified">

<xs:element name="book">
<xs:complexType>
<xs:sequence>
<xs:element name="isbn" type="xs:string" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="isbn" type="xs:string"/>
</xs:complexType>

<xs:key name="dummy">
<xs:selector xpath="."/>
<xs:field xpath="isbn|@isbn"/>
</xs:key>

</xs:element>

</xs:schema>

Now, if the isbn attribute (only) is present, it validates fine. But if
the
isbn child (only) is present, I get the following validation error:

The identity constraint 'http://www.example.com:dummy' validation has
failed
due to either a key is missing or the exsisting key has an empty node.

And if both the attribute and child are present, I get no validation error
(which is wrong).

I am using Visual Studio .NET, hence the .NET Framework version 1.0. Am I
experiencing a limitation in Microsoft's support for XML Schema, or am I
missing something? Any insights appreciated!
Eric W. Sirko

Nov 12 '05 #2
Thanks, that makes sense. But it makes no difference (well, maybe it's
different, but it still doesn't work properly). The Microsoft validating
parser just blows, I guess..

Eric
"Priscilla Walmsley" <no****@datypic.com> wrote in message
news:#h**************@TK2MSFTNGP11.phx.gbl...
Hi Eric,

XPath expressions like (isbn|@isbn) are not affected by default namespace
declarations. Therefore, you must assign a prefix to the target namespace
and use that prefix in the XPath expression, or it won't find the isbn
element. So, it should look like this:

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema targetNamespace="http://www.example.com"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:ex="http://www.example.com"
elementFormDefault="qualified">

<xs:element name="book">
<xs:complexType>
<xs:sequence>
<xs:element name="isbn" type="xs:string" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="isbn" type="xs:string"/>
</xs:complexType>

<xs:key name="dummy">
<xs:selector xpath="."/>
<xs:field xpath="ex:isbn|@isbn"/>
</xs:key>

</xs:element>

</xs:schema>

Hope that helps,
Priscilla
------------------------------------------------------------------
Priscilla Walmsley
Author, Definitive XML Schema / XML in Office 2003
http://www.datypic.com
------------------------------------------------------------------

"Eric W. Sirko" <es****@sw-sol.com> wrote in message
news:ed*************@TK2MSFTNGP12.phx.gbl...
Hi,

Eric van der Vlist's book XML Schema says that we can use xs:key to
declare
co-occurrence constraints. The example he uses (boiled down a bit) is a
"book" element that must have either an "isbn" attribute or an "isbn"
child
element, but not both:

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema targetNamespace="http://www.example.com"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.example.com"
elementFormDefault="qualified">

<xs:element name="book">
<xs:complexType>
<xs:sequence>
<xs:element name="isbn" type="xs:string" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="isbn" type="xs:string"/>
</xs:complexType>

<xs:key name="dummy">
<xs:selector xpath="."/>
<xs:field xpath="isbn|@isbn"/>
</xs:key>

</xs:element>

</xs:schema>

Now, if the isbn attribute (only) is present, it validates fine. But if
the
isbn child (only) is present, I get the following validation error:

The identity constraint 'http://www.example.com:dummy' validation has
failed
due to either a key is missing or the exsisting key has an empty node.

And if both the attribute and child are present, I get no validation error (which is wrong).

I am using Visual Studio .NET, hence the .NET Framework version 1.0. Am I experiencing a limitation in Microsoft's support for XML Schema, or am I
missing something? Any insights appreciated!
Eric W. Sirko


Nov 12 '05 #3

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

Similar topics

8
by: Malcolm Clift | last post by:
Hi All, Using wx, I'm trying to draw all items in a range of 50 in a text at certain co -ordinates (a simply textwrap) . A while back Alex Martelli was kind enough to give me the following to...
0
by: melledge | last post by:
Mozilla Foundation Co-Hosts Europe's Leading XML and Web Developer Conference XTech 2005 Conference to Bring Together XML and Web Technology Thought Leaders
1
by: Lee J. Moore | last post by:
I've spent a day writing software that will generate a multi-page/level family tree from a single HTML template and a Gedcom file, yet what seems like a minor issue with the CSS in the template is...
1
by: relisoft | last post by:
SEATTLE, Washington. - July 12, 2006: Reliable Software® announces the upcoming release of Code Co-op® version 5.0. Code Co-op is an affordable peer-to-peer version control system for distributed...
2
by: Mike | last post by:
I am using a server-side component for resizing/cropping images. Cropping is possible if I know the co-ordinates. I want to be able to offer users the ability to specify their own co-ordinates. ...
5
by: dm3281 | last post by:
Hi all -- We currently have an ecommerce application installed on a W2K Advanced server running .NET 1.1. In November, I installed .NET 2.0 in order to allow a Windows Forms application I...
8
by: john | last post by:
To test a new piece of software designed to help with (among other things) eCommerce WWW site development. The software is fairly easy to use but you must fit a profile. Retail price is 120 GBP and...
1
by: kailashchandra | last post by:
Hello Everybody i am trying to get co-ordinate position of mouse using java script using the following code.it works fine on IE and other but it is not working on mozilla.i couldn't...
1
by: =?Utf-8?B?QWJoaXNoZWsgUmFp?= | last post by:
Hi, I am working on the application which is based on the co-ordinate system it will support on different language(Globalization). My problem is to how can get relative co-ordinate in different...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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
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,...
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.