End Google Ads 201810 - BS.net 01 --> Hello Everyone,

I have a very small problem which I cant seem to fix. The following is the code which validates an XML file against a Schema. As the XML file gets parsed, if there is an XMLException in the XML file, the error message indicates the error and outputs the message along with the Line and position. But if there is a XMLSchemaException, it indicates the error but does not tell me the line and position number.


try
{
XmlDocument doc = new XmlDocument();
doc.Load(strXML);
string xmlFrag = doc.InnerXml;
XmlParserContext context = new XmlParserContext(null, null, "", XmlSpace.None);
reader = new XmlValidatingReader(xmlFrag, XmlNodeType.Element, context);
reader.ValidationType = ValidationType.Schema;
myschema.Add("http://tempuri.org/dsMinistryH1N1Export.xsd", strXSD);
reader.Schemas.Add(myschema);
//reader.ValidationEventHandler += new ValidationEventHandler(ShowCompileErrors);
//reader.ValidationEventHandler += new ValidationEventHandler(ValidationHandler);

while (reader.Read())
{


}

output.Text = ("Completed Validating " + strXML);
}

catch (XmlException XmlExp)
{
output.Text = ("XMLException " + XmlExp.Message);

}

catch (XmlSchemaException XmlSchExp)
{
output.Text = ("XMLSchemaException:" + XmlSchExp.Message);


}

//Catch all other exceptions and report them to the user:
catch (Exception GenExp)
{
output.Text = ("Exception " + GenExp.Message);
}


Note: I have tried using XmlSchExp.LineNumber and XmlSchExp.LinePosition - The problem is I need the user to be able to fix the error in the XML file, not the Schema File. So how do I output the Line/Position of where the error is in the XML file once the reader catches the XML schemaException. I hope I am clear about my question. Thanks in advance for any help.