Validating XML against DTD

May 21 2007 7:54 AM
I am trying to validate a XML with an external DTD in .NET 2003. In case of missing elements, the XMLValidatingReader returns the error but if any required attribute is missing, it validates successfuilly. The same code is running fine in .NET 2005. Is the XML parser in .NET 2003 not apt to validate required or missing attributes. My code snippet is

private void btnValidate_Click(object sender, System.EventArgs e)
{
try

{

XmlTextReader oReader = new XmlTextReader(sMainFilePath);

oReader.Normalization = true;

XmlValidatingReader oValidator = new XmlValidatingReader(oReader);

oValidator.XmlResolver = new MyCustomResolver(sPath);

oValidator.ValidationType = ValidationType.DTD;

oValidator.ValidationEventHandler +=new ValidationEventHandler(oValidator_ValidationEventHandler);

while (oValidator.Read())

{

Console.Write(oValidator.Name + "\n");

}

MessageBox.Show(sValidateMsg);

}

catch ( Exception oEx )

{

Console.Write(oEx);

}

}

private void oValidator_ValidationEventHandler(object sender, ValidationEventArgs e)

{

sValidateMsg += e.Message;

}

Any help would be appreciated

Regards
GS