473,837 Members | 1,578 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with Schema Validations using XmlValidatingRe ade--HELP

I Have 2 separate schemas.

--------------Schema 1 is defined as below-----------
<xs:schema targetNamespace ="http://Schemas/1" xmlns="http://Schemas/1" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefa ult="qualified" attributeFormDe fault="unqualif ied">
<xs:element name="Loan">
<xs:complexType >
<xs:sequence>
<xs:element name="Borrower" maxOccurs="unbo unded">
<xs:complexType >
<xs:attribute name="BorrID" use="required">
<xs:simpleTyp e>
<xs:restricti on base="xs:int">
<xs:minInclusiv e value="1"/> <!--THIS IS WHAT CAUSES PROBLEMS -->
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:unique name="BID">
<xs:selector xpath="Borrower "/>
<xs:field xpath="@BorrID"/>
</xs:unique>
</xs:element>
</xs:schema>

--------------END Schema 1-----------------------------

--------------Schema 2 is defined as below-----------
<xs:schema targetNamespace ="http://Schemas/2" xmlns="http://Schemas/2" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefa ult="qualified" attributeFormDe fault="unqualif ied">
<xs:element name="LEAD_INFO ">
<xs:complexType >
<xs:sequence>
<xs:element name="Borrower" maxOccurs="unbo unded">
<xs:complexType >
<xs:attribute name="BorrID" use="required">
<xs:simpleTyp e>
<xs:restricti on base="xs:int">
<xs:minInclusiv e value="1"/> <!--THIS IS WHAT CAUSES PROBLEMS -->
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

--------------END Schema 2-----------------------------

Notice the use of "minInclusi ve/maxInclusive" attribs on Borrower

For all intents and purposes, the two schemas were meant for different purposes. The third schema intends to tie the two schemas together as below

--------------Schema 3 is defined as below-----------
<xs:schema targetNamespace ="http://Schemas/3" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:s3="http://Schemas/3" xmlns:s1="http://Schemas/1" xmlns:s2="http://Schemas/2" elementFormDefa ult="qualified" attributeFormDe fault="unqualif ied">
<xs:import namespace="http ://Schemas/2" schemaLocation= "Schema2.xs d"/>
<xs:import namespace="http ://Schemas/1" schemaLocation= "Schema1.xs d"/>
<xs:element name="ROOT">
<xs:complexType >
<xs:sequence>
<xs:element ref="s1:Loan"/>
<xs:element ref="s2:LEAD_IN FO"/>
</xs:sequence>
</xs:complexType>
<xs:keyref name="B2" refer="s3:B1">
<xs:selector xpath="s2:LEAD_ INFO/s2:Borrower"/>
<xs:field xpath="@BorrID"/>
</xs:keyref>
<xs:key name="B1">
<xs:selector xpath="s1:Loan/s1:Borrower"/>
<xs:field xpath="@BorrID"/>
</xs:key>
</xs:element>
</xs:schema>

--------------END Schema 3-----------------------------

Note that I am trying to enforce Ref integrity using key/keyref
--------------The Sample XML is as below----------------
<ROOT xmlns="http://Schemas/3" xmlns:s1="http://Schemas/1" xmlns:s2="http://Schemas/2" xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
<Loan xmlns="http://Schemas/1">
<Borrower BorrID="1"/>
</Loan>
<LEAD_INFO xmlns="http://Schemas/2">
<Borrower BorrID="1"/>
</LEAD_INFO>
</ROOT>

--------------END SAMPLE-----------------------------------

The Code Snippet in C# is as below (I know the code is not perfect but please bear with me.)
-----------------------------------------------------------------
StreamReader s= System.IO.File. OpenText(@"C:\W ork\ELIS\Sample .xml");
string xmlFrag =s.ReadToEnd();
NameTable nt = new NameTable();
XmlNamespaceMan ager nsmgr = new XmlNamespaceMan ager(nt);
XmlParserContex t context = new XmlParserContex t(null, nsmgr, null, XmlSpace.None);
reader = new XmlValidatingRe ader(xmlFrag, XmlNodeType.Ele ment, context);
reader.Schemas. Add("http://Schemas/3", @"file:///Schema3.xsd");
reader.Validati onType=Validati onType.Schema;
reader.Validati onEventHandler+ =new ValidationEvent Handler(Validat ionEventHandle) ; //PLEASE ADD A VALIDATION HANDLER
while (reader.Read()) {} //Loop through elements
//f you reach here without hitting validations, you are OK
MessageBox.Show ("DONE");
----------------End Code Snippet------------------------------

The Problem is that when I run the code snippet, I get the error
"The key sequence '1' in Keyref fails to refer to some key. An error occurred at , (10, 4)." I checked the XML with XMLSPY and it does not report any validation problems.

Anyway, the moment I took the minInclusive/maxInclusive restrictions off, the error disappears.

The Schemas that work with the same Sample.Xml (and the same tieing schema (Schema3) are as below

--------------Schema 1 is defined as below-----------
<xs:schema targetNamespace ="http://Schemas/1" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://Schemas/1" elementFormDefa ult="qualified" attributeFormDe fault="unqualif ied">
<xs:element name="Loan">
<xs:complexType >
<xs:sequence>
<xs:element name="Borrower" maxOccurs="unbo unded">
<xs:complexType >
<xs:attribute name="BorrID" type="xs:int" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:unique name="BID">
<xs:selector xpath="Borrower "/>
<xs:field xpath="@BorrID"/>
</xs:unique>
</xs:element>
</xs:schema>
--------------END Schema -----------
--------------Schema 2 is defined as below-----------
<xs:schema targetNamespace ="http://Schemas/2" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://Schemas/2" elementFormDefa ult="qualified" attributeFormDe fault="unqualif ied">
<xs:element name="LEAD_INFO ">
<xs:complexType >
<xs:sequence>
<xs:element name="Borrower" maxOccurs="unbo unded">
<xs:complexType >
<xs:attribute name="BorrID" type="xs:int" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
--------------END Schema -----------

Notice that the simpletype under borrower are missing (For minInclusive/maxInclusive restriction)

Can you guys please help me.

Thanks in advance for all your help. To me it seems like a bug in .NET.
Rajesh

Nov 12 '05 #1
0 1730

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

Similar topics

1
6401
by: Naresh Agarwal | last post by:
Hi I'm using SAX Parser of Xerces Java v2.4.0 for XML Parsing. I want to perform schema validations on the xml. The problem is that root element of XML document does not have "xsi:schemaLocation" attribute, which is used to specify the .xsd file. Is there any other way for specifying the name of .xsd file?
2
1544
by: Rajesh Jain | last post by:
I Have 2 separate schemas. --------------Schema 1 is defined as below----------- <xs:schema targetNamespace="http://Schemas/1" xmlns="http://Schemas/1" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xs:element name="Loan"> <xs:complexType> <xs:sequence> <xs:element name="Borrower" maxOccurs="unbounded"> <xs:complexType> <xs:attribute name="BorrID" use="required">
1
2328
by: Dan Bass | last post by:
There's an XML message I have, that has no namespace information. Then there is a XSD schema that is must validate against, but this has a targetNamespace and xmlns of "http://www.wbf.org/xml/b2mml-v02". How do I get this XML to validate against the Schema in C#? If I use XmlSpy (2005 home edition) to perform the validation, it first inserts namespace and schema information into the XML before validating. Validation then seems to work if...
1
2320
by: Wallace | last post by:
Hi all, I have a problem on validating a xml fragment using a single namespace schema which spread across multiple schema files using include in the master schema file. No matter how I change the xml fragment (to include default namespace xmlns='urn:xxx:yy' and any other namespace it may have), I still get the same error. 'urn:xxx:yy:Header' element is not declared. An error occurred at , (1, 2).
1
1382
by: Whoever | last post by:
See below. The WSDL looks good, the result is OK but not Schema. Where and how should I put it in. Hopfully not manually. Thanks. public class aUser { public string UserID { get {...} set {...} public string UserName {...} } public class UserList : System.Collection.CollectionBase { public void Add(aUser user) {...}
1
3563
by: harishkumar | last post by:
hi this is hari how to write the email id checking in javascript validations using in vb.net 1) if u r cecking in email id this types of message to delever to user a)(.) dot is missing b) two @ are not accepting c) last dot after use(.com (or) co.in(or).in(or).net (or).org (or).uk and etc... please any one known give me reply thank u
0
2006
by: cty | last post by:
Title: Problem in session using php5 Good day, I use php5+mySQL4+IIS5.x Previuosly i use php4 and no error occur,
3
1395
by: 33sparsh | last post by:
Hi, i am new to XML. i want to validate user input data with .XSD file(before saving the data in xml file) . how can i validate it through the .net code. validate xml file with .xsd is ok,any data is mismatch it will throw error. But what my requirement is when user enter a value in text box(user name) this user name attribute had a definition in .xsd . According to given schema definition the control will be validated when i click...
2
3020
by: swethak | last post by:
hi , i write the code in .htm file. It is in cgi-bin/searches/one.htm.In that i write a form submitting and validations.But validations are not worked in that .htm file. I used the same code in my local system that validations work.plz tell that whats the problem in that. Here is my code <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html...
0
9695
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
10583
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...
1
10642
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
10286
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
9420
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...
1
7824
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
5863
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4060
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3128
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.