I got this weird error when I wanted to validate my in-memory xml Schema, anything I did wrong?
[Test]
public void ValidationXML()
{
int errorCount = 0;
var xmlString = "<?xml version='1.0'?><response><error code='1'> Success</error></response>";
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.LoadXml(xmlString);
xmlDocument.Validate((sender, e) => errorCount++);
Assert.AreEqual(0, errorCount);
}
The exception was:
failed: System.InvalidOperationException : The XmlSchemaSet on the document is either null or has no schemas in it. Provide schema information before calling Validate.
at System.Xml.XmlDocument.Validate(ValidationEventHandler validationEventHandler, XmlNode nodeToValidate)
at System.Xml.XmlDocument.Validate(ValidationEventHandler validationEventHandler)