"Amar" <amaretos@yahoo.com> wrote in message
news:7c627043.0407130725.5d0a9b8c@posting.google.com...
> Hi everyone, I am trying now for 4-5 hours to write a simple code to
> validate a very simple XML and i still get an error. Here is my Code,
> and i always 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;
> }
> }
>
> HERE IS 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>
>
> HERE IS 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>
>
>
> Please if anyone knows help!!
>
> Thanks