Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old February 27th, 2006, 03:15 AM
Eric M L
Guest
 
Posts: n/a
Default .NET 2.0 XML Validation - Exception sets LineNumber=0 and LinePosition=0

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;
}

  #2  
Old March 8th, 2006, 04:35 PM
Zafar Abbas
Guest
 
Posts: n/a
Default 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]


 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles