I am trying to validate an xml file via a .dtd. I have write this validator:
public bool Validation(XmlDocument xmlDoc)
{
var xml = XmldocToString(xmlDoc);
var r = new XmlTextReader(new StringReader(xml));
var settings = new XmlReaderSettings();
var sb = new StringBuilder();
settings.ProhibitDtd = false;
settings.ValidationType = ValidationType.DTD;
settings.ValidationEventHandler += (a, e) =>
{
sb.AppendLine(e.Message);
_isValid = false;
};
XmlReader validator = XmlReader.Create(r, settings);
while (validator.Read())
{
}
validator.Close();
return _isValid;
}
The problem is that I must have the dtd file in bin directory of the Solution. I want to chose a diferent directory to keep the .dtd file and i really can’t find how.
Thank you for your time.
Declare in the Xml file the association with the DTD:
Example in case the dtd is stored in a remote server:
Take a look at that wiki page and at that site for more options and information about Xml files and DTD association.
Example in case the dtd is placed locally (SYSTEM):
(Excerpt from here)