I'm trying to validate an XML feed against the ONIX 2.1 dtd. When I load the generated XML file into XMLSpy and validate against the DTD, it tells me that the feed is valid.
When I try to validate the same file using C# and XmlReader, I receive errors that child nodes are invalid despite being validated earlier by the 3rd party tool. What do I need to do in order to ensure that my code using XmlReader is correctly reading the dtd and validating appropriately?
Here's my code...
XmlReaderSettings settings = new XmlReaderSettings();
settings.ProhibitDtd = false;
settings.ValidationType = ValidationType.DTD;
settings.ValidationFlags = XmlSchemaValidationFlags.ReportValidationWarnings;
settings.ValidationEventHandler += new ValidationEventHandler(delegate(object sender, ValidationEventArgs args)
{
isXmlValid = false;
xmlValMsg.AppendLine(args.Message);
});
The problem could be with the DTD. There is an online DTD and Schema validator that you could try...
http://www.validome.org/grammar/
You could try to validate against the XSD instead. The Onix 2.1 xsd is available at http://www.editeur.org/15/Previous-Releases/#R%202.1%20Downloads. You will have to set the default namespace:
When loading the xml, turn off DTD parsing: