469,889 Members | 1,273 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,889 developers. It's quick & easy.

XmlValidatingReader gives me an error

I am writing a program to validate a XML file and i am getting an error.
Here is my Code, and i get an error at "args.Exception"

("The 'urn:books:catalog' element is not declared. An error occurred
at file:///c:/inetpub/wwwroot/LakisService/books.xml, (2, 2).")

private void Button2_Click(object sender, System.EventArgs e) {
XmlTextReader r = new XmlTextReader(Server.MapPath("books.xml"));
XmlSchema xs = new XmlSchema();
xs.SourceUri = Server.MapPath("books.xsd");

XmlValidatingReader v = new XmlValidatingReader(r);
v.ValidationType = ValidationType.Schema;
v.ValidationEventHandler += new ValidationEventHandler(MyValidation);
while (v.Read()){

public static void MyValidation(object sender, ValidationEventArgs
string strErr="";
if (args.Exception != null){
strErr = args.Message;

<?xml version="1.0" encoding="utf-8" ?>
<x:catalog xmlns:x="urn:books">
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<description>An in-depth look at creating applications with

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="catalog">
<xsd:element name="book" minOccurs="0" maxOccurs="unbounded">
<xsd:element name="author" type="xsd:string" />
<xsd:element name="title" type="xsd:string" />
<xsd:element name="genre" type="xsd:string" />
<xsd:element name="price" type="xsd:float" />
<xsd:element name="publish_date" type="xsd:date" />
<xsd:element name="description" type="xsd:string" />
<xsd:attribute name="id" type="xsd:string" />

Give me your suggestions to solve this,,,

Jul 21 '05 #1
0 987

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Ed Bacon | last post: by
3 posts views Thread by Nuevo Registrado | last post: by
reply views Thread by Harold Putman | last post: by
5 posts views Thread by Geoff | last post: by
reply views Thread by Sangeetha Nagaraj | last post: by
1 post views Thread by Plop69 | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.