Validate xml against DTD
-
Hi guys, Hope you are doing well. I have a Onix complaint XML document that I want to validate it with some Onix complaint DTD. I did coding for same in C# XmlReaderSettings settings = null; try { string xmlPath = Server.MapPath("XML/nielsen_onix.XML"); //Load XML into XmlTextReader // reader = new XmlTextReader(xmlPath); //Load XmlTextReader into XmlValidatingReader settings = new XmlReaderSettings(); //Set the validation type settings.ValidationType = ValidationType.DTD; settings.ProhibitDtd = false; settings.CheckCharacters = false; //Hook up the XmlValidatingReader’s //ValidationEventHandler to a call //back method named ValidationCallBack settings.ValidationEventHandler += new ValidationEventHandler( this.ValidationCallBack); XmlReader reader = XmlReader.Create(xmlPath, settings); //Read through the XML document by calling //the Read() method while (reader.Read()) { } //Check boolean field named valid (located at top of code) if (valid) Response.Write("Validation is Successful!"); reader.Close(); } catch(Exception ex) { Response.Write(ex.Message); } This code runs good and show the xml file invaid while my xml file is valid when I validated it on http://www.w3schools.com/XML/xml_validator.asp[^] Could you please check what's wrong going with me? Any help would be highly appreciable. Thanks Rohit