Hi,
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.Schemas.Add(xs);
v.ValidationType = ValidationType.Schema;
v.ValidationEventHandler += new ValidationEventHandler(MyValidation);
while (v.Read()){
}
v.Close();
}
public static void MyValidation(object sender, ValidationEventArgs
args){
string strErr="";
if (args.Exception != null){
strErr = args.Message;
}
}
XML FILE
--------------
<?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>
<genre>Computer</genre>
<price>44.95</price>
<publish_date>2000-10-01</publish_date>
<description>An in-depth look at creating applications with
XML.</description>
</book>
</x:catalog>
XSD FILE
---------------
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="catalog">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="book" minOccurs="0" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<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:sequence>
<xsd:attribute name="id" type="xsd:string" />
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
Give me your suggestions to solve this,,,
--
Rgds,
Sang