Hi,
I have created an XSD file which I want to use to validate XML files against. I am using the following code to do the validation
using (XmlReader reader = XmlReader.Create(fileUpload.PostedFile.InputStream)) {
XmlSchemaSet sc = new XmlSchemaSet();
sc.Add("", Request.PhysicalApplicationPath + "UploadRfid.xsd");
try {
XDocument doc = XDocument.Load(reader);
doc.Validate(sc, new ValidationEventHandler(ValidationCallback));
}
catch (XmlException exc) {
}
finally {
}
}
If I test this using an XML file with no namespaces or XSD declarations, it works fine and gives expected result (i.e. validates againast my schema).
However when I test this with a different XML file (which is nothing like my schema) that has inline XSD specified (not my one), the validation succeeds and does not get any errors even though the XML file is nothing like my schema.
My schema document begins with
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="myschema" xmlns:xs="http://www.w3.org/2001/XMLSchema">
How can I get the second XML to fail my schema validation?