Error trying to validate XML against XSD

videnteonline

New Member
Im trying to create an XML validator using the following code\[code\]static void Main(string[] args) { string xmlUri = File.ReadAllText("G:\\test.xml"); Console.WriteLine(xmlUri); string xsdUri = File.ReadAllText("G:\\test.xsd"); Console.WriteLine(xsdUri); Console.Write(ValidateXmlWithXsd(xmlUri, xsdUri)); Console.Read(); } private static bool ValidateXmlWithXsd(string xmlUri, string xsdUri) { try { XmlReaderSettings xmlSettings = new XmlReaderSettings(); xmlSettings.Schemas = new System.Xml.Schema.XmlSchemaSet(); xmlSettings.Schemas.Add("myNamespace", xsdUri); xmlSettings.ValidationType = ValidationType.Schema; XmlReader reader = XmlReader.Create(xmlUri, xmlSettings); // Parse the file. while (reader.Read()) ; return true; } catch (Exception ex) { Console.WriteLine("Error occured at ", ex.StackTrace);//1 return false; } }\[/code\]the execution of the code returns \[code\]False\[/code\] despite the fact , that the XML perfectly conforms to the XSD. Also Im not being able to print the error message at line marked 1. to figure out whats happening. A screenshot of the output is below.
GASX2uq2
http://pastebin.com/GASX2uq2XSD File:
 
Back
Top