Re: .NET 2.0 XML Validation - Exception sets LineNumber=0 and LinePosition=0
line number and line position should be set in a schema validation
exception, please post the XSD and XML that you are using. Your code looks
OK.
Thanks,
Zafar
"Eric M L" <emleml@hotmail.com> wrote in message
news:1141009469.664005.133950@z34g2000cwc.googlegr oups.com...[color=blue]
> I am wondering if I am alone with this problem. Using VS 2005, I must
> validate an XML file via a Schema and it works well. When I get the
> schema exception and check the LineNumber and LinePosition properties,
> they are always set to 0 <===
>
> Here are 2 ways I used to validate the XML always getting LineNumber
> and LinePosition = 0.
> Any hints would be greatly appreciated.
>
> ================================================== ================
>
> XmlReaderSettings settings = new XmlReaderSettings();
> settings.IgnoreWhitespace = false;
> settings.Schemas.Add(Schema);
> settings.ValidationType = ValidationType.Schema;
> FileStream stXml = new FileStream(sXmlFile,
> FileMode.Open);
> XmlReader xrdr = XmlReader.Create(stXml, settings);
> try
> {
> while (xrdr.Read());
> }
> catch (XmlException ex)
> {
> sMessage = "XML Format error in Xml file: " +
> sXmlFile + " ===> " + ex.Message;
> return false;
> }
> catch (XmlSchemaValidationException ex)
> {
> sMessage = "Error in Xml file: " + sXmlFile + " at
> line " +
> ex.LineNumber + ", column " + ex.LinePosition +
> ": " + ex.Message;
> return false;
>
> string s = ex.Message + " (line " +
> settings.LineNumberOffset + "." + settings.LinePositionOffset + ")";
> }
> xrdr.Close();
> stXml.Close();
>
> ================================================== ===============
>
> XmlDocument Xml = new XmlDocument();
> Xml.Schemas.Add(Schema);
> Xml.PreserveWhitespace = true;
>
> try
> {
> Xml.Load(sXmlFile);
> Xml.Validate(null);
> }
> catch (XmlException ex)
> {
> sMessage = "XML Format error in Xml file: " +
> sXmlFile + " ===> " + ex.Message;
> return false;
> }
> catch (XmlSchemaValidationException ex)
> {
> sMessage = "Error in Xml file: " + sXmlFile + " at
> line " +
> ex.LineNumber + ", column " + ex.LinePosition +
> ": " + ex.Message;
> return false;
> }
>[/color]
|