all groups > dotnet xml > february 2006 >
You're in the

dotnet xml

group:

.NET 2.0 XML Validation - Exception sets LineNumber=0 and LinePosition=0


.NET 2.0 XML Validation - Exception sets LineNumber=0 and LinePosition=0 Eric M L
2/26/2006 7:04:29 PM
dotnet xml:
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;
}
Re: .NET 2.0 XML Validation - Exception sets LineNumber=0 and LinePosition=0 Zafar Abbas
3/8/2006 8:19:56 AM
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

[quoted text, click to view]

AddThis Social Bookmark Button