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

Issues when validating xml in VS2003

I am trying to validate an xml file and schema and when I
am trying to validate I am getting the following error. I
have been trying to come out with a solution but I have
failed so far. The document validates ok in xmlSpy but it
fails in VS2003. Is there any article or fix for this?

Thnaks in advance.

Error:
======
"The Keyref 'Details' cannot find referred key or unique
in scope. An error occurred at file:///C:/test1.xml, (7,
4)..\n"
XML file:
<?xml version="1.0" encoding="UTF-8"?>
<Renewals>
<Renewal>
<Headers>
<e1>String</e1>
</Headers>
<Details>
<e1>String</e1>
<e2>0</e2>
</Details>
</Renewal>
</Renewals>

XSD file:
=========
<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XMLSPY v5 rel. 4 U
(http://www.xmlspy.com) by Tomas Rivas (Tyco Healthcare-
Kendall) -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xs:element name="Renewals">
<xs:annotation>
<xs:documentation>Renewal
document</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element
name="Renewal">
<xs:complexType>

<xs:sequence>

<xs:element ref="Headers"/>

<xs:element ref="Details"/>

</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Headers">
<xs:complexType>
<xs:sequence>
<xs:element name="e1"
type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:key name="key1">
<xs:selector
xpath=".//Renewals/Renewal/Headers"/>
<xs:field xpath="e1"/>
</xs:key>
</xs:element>
<xs:element name="Details">
<xs:complexType>
<xs:sequence>
<xs:element name="e1"
type="xs:string"/>
<xs:element name="e2"
type="xs:int"/>
</xs:sequence>
</xs:complexType>
<xs:keyref name="fKey" refer="key1">
<xs:selector
xpath=".//Renewals/Renewal/Details"/>
<xs:field xpath="e1"/>
</xs:keyref>
</xs:element>
</xs:schema>

=====================================
The code I am using is the following:
=====================================

public string ValidateXml(string inXMLLocation, string
inXSDLocation)
{
string errorsList = string.Empty;
try
{
// Read the xml file, and send this to
validator.
XmlTextReader xmlReader = new
XmlTextReader(inXMLLocation);

// load the schema file into an
XmlTextReader object
XmlTextReader xsdReader = new
XmlTextReader(inXSDLocation);
XmlSchemaCollection sc = new
XmlSchemaCollection();

// add the ValidationEventHandler to the
schema collection
sc.ValidationEventHandler += new
ValidationEventHandler(ValidationCallBack);
// add the schema to the
XmlSchemaCollection object
sc.Add("", xsdReader);
// create an XmlValidatingReader object
based on the Xml document
XmlValidatingReader rdr = new
XmlValidatingReader(xmlReader);

// set the ValidationType to a schema
rdr.ValidationType =
ValidationType.Schema;
rdr.Schemas.Add(sc);

rdr.ValidationEventHandler += new
ValidationEventHandler(ValidationCallBack);

while (rdr.Read());

errorsList = validationErrors;

//closing the readers and releasing the
handlers to the IFS docs.
//These readers were locking the files
when saving them to the IFS.
xmlReader.Close();
xsdReader.Close();
}
catch(Exception exc)
{
throw new Exception(string.Format("An
exception has occurred when executing method {0}.", (new
StackFrame()).GetMethod().Name), exc);
}
finally
{}
return errorsList;
}

Nov 12 '05 #1
0 952

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

Similar topics

4
by: Tomas Rivas | last post by:
I am trying to validate an xml file and schema and when I am trying to validate I am getting the following error. I have been trying to come out with a solution but I have failed so far. The...
2
by: Tomas Vera | last post by:
Hello All, I'm running into a problem that I don't know how to solve (properly, at least). Our web servers are running Win2K and have Framework v1.0.3705 running on them. We have a DLL...
0
by: PeacError | last post by:
Using Microsoft Visual Studio .NET 2003, Visual C# .NET 1.1: I apologize if this question has been addressed elsewhere, but I could not find a reference to it in the search engine for this...
10
by: Skip | last post by:
Can anybody tell me if there is a list/discussion anywhere about possible problems/issues/differences when upgrading a desktop app from VS2002 to VS2003? I have an app that uses...
5
by: Stewart | last post by:
Pressing a Save Button on a Toolbar will not bind or validate the last value entered in a text box. I have found that when clicking on the Toolbar the focus in the binded text box does not leave. ...
0
by: ML | last post by:
We have a rather large vb.net winform app that multiple users access via sessions on s terminal server. We are running into issues where the application seems to be bogging down the terminal...
23
by: _AnonCoward | last post by:
I'm looking to purchase VS 2005 some time in the near future. I've read a lot of grief on the web and in this ng as to the flaws and problems with the VS 2005 release (and I understand MS is coming...
1
by: Bonggoy Cruz | last post by:
We have a fairly big size ASP.NET web application that was written VB.NET. We are in the process converting the web project. We used the migration wizard included in VS 2005. I followed step by...
2
by: rajninathpatil | last post by:
Hi all, I get the following linker error when compiling a project written in VS2003. net How do I solve this ? Here are two more errors :
4
by: darrel | last post by:
Looks like we're getting Vista soon. Alas, we're still maintaining a few apps in 1.1 using VS.2003. Are there any issues? Does it run on Vista? I found this which appers that MS doesn't...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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...
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...

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.