473,657 Members | 2,475 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Does XmlValidatingRe ader check key and keyref constrains?

Hi

I have a question
whether XmlValidatingRe ader doesn't check keyref constrain (the same with
key constraint) or I do smth wrong.

I have the following schema

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="module" targetNamespace ="http://tempuri.org/module.xsd"
xmlns="http://tempuri.org/module.xsd"
xmlns:mstns="ht tp://tempuri.org/module.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="u rn:schemas-microsoft-com:xml-msdata">
<xs:element name="module">
<xs:complexType >
<xs:sequence>
<xs:sequence>
<xs:element ref="type" maxOccurs="unbo unded" />
<xs:element ref="object" maxOccurs="unbo unded" />
</xs:sequence>
</xs:sequence>
</xs:complexType>
<xs:key name="typeNameK ey">
<xs:selector xpath=".//type" />
<xs:field xpath="@name" />
</xs:key>
<xs:key name="objectNam eKey">
<xs:selector xpath=".//object" />
<xs:field xpath="@name" />
</xs:key>
<xs:keyref name="typeOfObj ect" refer="typeName Key">
<xs:selector xpath=".//object" />
<xs:field xpath="@ofType" />
</xs:keyref>
</xs:element>
<xs:element name="type">
<xs:complexType >
<xs:sequence />
<xs:attribute name="name" type="xs:NMTOKE N" />
</xs:complexType>
</xs:element>
<xs:element name="object">
<xs:complexType >
<xs:sequence />
<xs:attribute name="name" type="xs:NMTOKE N" />
<xs:attribute name="ofType" type="xs:NMTOKE N" />
</xs:complexType>
</xs:element>
</xs:schema>

and read the file

<?xml version="1.0" encoding="utf-8" ?>
<module xmlns="http://tempuri.org/module.xsd">
<type name="A" />
<type name="B" />
<object name="o1" ofType="A" />
<object name="o2" ofType="A" />
<object name="o3" ofType="B" />
<object name="o4" ofType="B" />
<object name="o4" ofType="C" />
</module>

with the code

XmlTextReader reader = new XmlTextReader(@ "../../module1.xml");
XmlValidatingRe ader vreader = new XmlValidatingRe ader(reader);
vreader.Schemas .Add(@"http://tempuri.org/module.xsd",
@"../../module.xsd");
vreader.Validat ionType = ValidationType. Schema;
vreader.Validat ionEventHandler += new
ValidationEvent Handler(vreader _ValidationEven tHandler);

XmlDocument doc = new XmlDocument();
doc.Load(vreade r);

But I don't get an error for <object name="o4" ofType="C" />.
So the question is whether XmlValidatingRe ader doesn't check keyref
constrain (the same with key constraint) or I do smth wrong.

Dima.
Nov 12 '05 #1
1 2858
The XPath expression in the selectors are not qualified with the
targetNamespace of the schema.
The XPath expression ".//object" selects object elements that not namespace
qualified, whereas you want the xpath to select all
http://tempuri.org/module.xsd:object elements

Changing the selectors to the following produces the following errors:
<xs:key name="typeNameK ey">
<xs:selector xpath="mstns:ty pe" />
<xs:field xpath="@name" />
</xs:key>
<xs:key name="objectNam eKey">
<xs:selector xpath="mstns:ob ject" />
<xs:field xpath="@name" />
</xs:key>
<xs:keyref name="typeOfObj ect" refer="typeName Key">
<xs:selector xpath="mstns:ob ject" />
<xs:field xpath="@ofType" />
</xs:keyref>

Exception Severity: Error
There is a duplicate key sequence 'o4' for
'http://tempuri.org/module.xsd:obje ctNameKey' key or unique identity
constraint.
An Error Occurred at: file:///D:/BugRepro/keyref.xml, (9,6)

Exception Severity: Error
The key sequence 'C' in Keyref fails to refer to some key.
An Error Occurred at: file:///D:/BugRepro/keyref.xml, (9,6)
5/18/2004 1:06:41 PM

Thanks,
Priya

"Dmitry Martynov" <do********@hot mail.com> wrote in message
news:u7******** ******@TK2MSFTN GP11.phx.gbl...
Hi

I have a question
whether XmlValidatingRe ader doesn't check keyref constrain (the same with
key constraint) or I do smth wrong.

I have the following schema

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="module" targetNamespace ="http://tempuri.org/module.xsd"
xmlns="http://tempuri.org/module.xsd"
xmlns:mstns="ht tp://tempuri.org/module.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="u rn:schemas-microsoft-com:xml-msdata">
<xs:element name="module">
<xs:complexType >
<xs:sequence>
<xs:sequence>
<xs:element ref="type" maxOccurs="unbo unded" />
<xs:element ref="object" maxOccurs="unbo unded" />
</xs:sequence>
</xs:sequence>
</xs:complexType>
<xs:key name="typeNameK ey">
<xs:selector xpath=".//type" />
<xs:field xpath="@name" />
</xs:key>
<xs:key name="objectNam eKey">
<xs:selector xpath=".//object" />
<xs:field xpath="@name" />
</xs:key>
<xs:keyref name="typeOfObj ect" refer="typeName Key">
<xs:selector xpath=".//object" />
<xs:field xpath="@ofType" />
</xs:keyref>
</xs:element>
<xs:element name="type">
<xs:complexType >
<xs:sequence />
<xs:attribute name="name" type="xs:NMTOKE N" />
</xs:complexType>
</xs:element>
<xs:element name="object">
<xs:complexType >
<xs:sequence />
<xs:attribute name="name" type="xs:NMTOKE N" />
<xs:attribute name="ofType" type="xs:NMTOKE N" />
</xs:complexType>
</xs:element>
</xs:schema>

and read the file

<?xml version="1.0" encoding="utf-8" ?>
<module xmlns="http://tempuri.org/module.xsd">
<type name="A" />
<type name="B" />
<object name="o1" ofType="A" />
<object name="o2" ofType="A" />
<object name="o3" ofType="B" />
<object name="o4" ofType="B" />
<object name="o4" ofType="C" />
</module>

with the code

XmlTextReader reader = new XmlTextReader(@ "../../module1.xml");
XmlValidatingRe ader vreader = new XmlValidatingRe ader(reader);
vreader.Schemas .Add(@"http://tempuri.org/module.xsd",
@"../../module.xsd");
vreader.Validat ionType = ValidationType. Schema;
vreader.Validat ionEventHandler += new
ValidationEvent Handler(vreader _ValidationEven tHandler);

XmlDocument doc = new XmlDocument();
doc.Load(vreade r);

But I don't get an error for <object name="o4" ofType="C" />.
So the question is whether XmlValidatingRe ader doesn't check keyref
constrain (the same with key constraint) or I do smth wrong.

Dima.

Nov 12 '05 #2

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

Similar topics

0
3269
by: peterpeter | last post by:
Hi. There is a XML schema problem that I have with key/keyref: I have two complex (A and B) types which both inherit from a common base typ (Base). A refers B using a xs:IDREF element named Ref_to_A. Both are allowed to be instantiated under the root element by declaring an element of the base class. I want to have type safety for the reference by using key/keyref.
0
1802
by: Markus Seibold | last post by:
Hello NG, sorry for pasting that much code but I just can't figure out how get the <key><keyref> to work in XML Schema. I am using XMLSpy 4.3 for editing my XML. I want to represent a recursive 1:n relationship between a database table AdminUnit (i.e., States consist of Counties).
5
6507
by: Russell O'Connor | last post by:
The following XML and Schema doesn't validate in Visual Studio .NET 2003. Is there some mistake I'm making, or is VS.NET in error. The error is r:\test2.xml(3): The key sequence 'foo' in Keyref fails to refer to some key. An error occurred at , (3, 6). Any help is appreciated. Here is the schema. <?xml version="1.0" ?> <xs:schema id="NewDataSet" targetNamespace="http://tempuri.org/test2.xsd" xmlns:mstns="http://tempuri.org/test2.xsd"
0
1220
by: mark.van.der.voort | last post by:
Hi, I have defined a simple key/keyref validation for describing a tree. <xs:key name="key_member"> <xs:selector xpath=".//member"/> <xs:field xpath="@id"/> </xs:key> <xs:keyref name="ref_parent_member" refer="key_member"> <xs:selector xpath=".//member"/>
18
5552
by: Vlad | last post by:
I have the following code: I have a local copy of the DTD that I need to validate incoming XML documents against. The XML document has the <!DOCTYPE myname SYSTEM "myfile.dtd"> define. When the following code is executed the XML gets resolved through the XMLResolver and gets correctly validated against the locally stored DTD file. The problem occurs when the incoming XML contains no DOCTYPE attribute. The resolver code never gets called...
2
2847
by: svestin | last post by:
Hi All! I run into a problem defining a XSD schema with KEYREF references. Is it possible to use KEYREF with nillable fields? Just like a database where a FK could be null. In the example below the tag <Owner> is nillable and also used as FIELD in the KEYREF.
1
1306
by: Wolfgang Uhr | last post by:
Hello I have the following problem. I want to use the validating parser XmlValidatingReader and so I write ... FileStream stream = new FileStream(ofd.FileName, FileMode.Open); XmlValidatingReader rdr = new XmlValidatingReader( stream, XmlNodeType.Element, null); rdr.ValidationEventHandler += eventHandler;
0
1185
by: mavis | last post by:
Does IntellJ support the checking for "keyref" definition? Why it seems does not work at all? <xs:key name="supported-platforms-name-unique"> <xs:selector xpath=".//supported-platforms/platform"/> <xs:field xpath="."/> </xs:key> <xs:keyref name="platforms-name-ref"
0
1636
by: peterpeter | last post by:
Hi. There is a XML schema problem that I have with key/keyref: I have a complex type "AExtended" which inherits from a base type "ABase". Both are allowed to be instantiated under the "Root" element by declaring an element of the base class with name "A" and either "xsi:type=ABase" or "xsi:type=AExtended". I want to have type safety for the reference "Ref_to_AExtended" from
0
8411
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
8323
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
8739
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8613
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
4173
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...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2740
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
2
1969
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1732
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.