I am running xhtml-strict report on a bunch of pages and each time I find a page on a specific page I save it. I need to really look over all the page but what happens is that sometimes the XmlReader is failling but I cannot go on and check the rest of the file to report the errors. I have Eventhandler catching dtd errors when found.
the errors i am getting or either Invalid token or, Error while parsing entity block. I tried to remove illegal characters but not stopping the errors.
public void Execute(string xml, string dtd) {
Errors = new List<string>();
XmlReaderSettings settings = new XmlReaderSettings();
settings.ProhibitDtd = false;
settings.ValidationType = ValidationType.DTD;
settings.ValidationEventHandler += new ValidationEventHandler( ValidationEventHandler );
// Create a local reference for validation
string newDoctype = string.Format("<!DOCTYPE html SYSTEM \"file://{0}\">", dtd);
// Replace the current doctype with the new local one
xml = Regex.Replace(xml, "<!DOCTYPE.*?>", newDoctype, RegexOptions.Singleline | RegexOptions.IgnoreCase);
XmlReader reader = XmlReader.Create( new System.IO.StringReader( xml ) , settings );
try {
while (reader.Read()) {
}
} catch (Exception ex) {
Errors.Add(ex.Message);
} finally {
if (reader != null) reader.Close();
}
This is what I have at the moment but it causing infinite loop, it never passing on to the next. Any kind of move or skip seems to be working.
Thanks for your help!