473,395 Members | 1,526 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

skipping invalid nodes with XmlTextReader

I want to do something like:

bool bContinueReading=true;
XmlTextReader Reader=new XmlTextReader("file.xml");
while(bContinueReading)
{
try
{
Reader.Read();
...
}
catch
{
Reader.Skip();
}
}

To skip over any xml formatting problems (invalid characters) in the file.
However, the Skip() function does not seem to move the cursor forward and an
infinite loop results when an error occurs.
Nov 12 '05 #1
3 2812
The code should read:

bool bContinueReading=true;
XmlTextReader Reader=new XmlTextReader("file.xml");
while(bContinueReading)
{
try
{
bContinueReading=Reader.Read();
...
}
catch
{
Reader.Skip();
}
}
Nov 12 '05 #2
Stephen S Kelley wrote:
To skip over any xml formatting problems (invalid characters) in the file.
However, the Skip() function does not seem to move the cursor forward and an
infinite loop results when an error occurs.


You can't by design. XML spec requires draconian error handling - any
malformed XML document must not be parsed successfully.

--
Oleg Tkachenko [XML MVP, MCAD]
http://blog.tkachenko.com
Nov 12 '05 #3
And the XmlReader implements this W3C XML Spec. The problem with error
recovery in general is it becomes ambiguous which is generally not good for
mission critical business applications. So you will have to employ a more
forgiving parser (see SgmlReader on www.gotdotnet.com for an example).

"Oleg Tkachenko [MVP]" <oleg@NO!SPAM!PLEASEtkachenko.com> wrote in message
news:et**************@TK2MSFTNGP10.phx.gbl...
Stephen S Kelley wrote:
To skip over any xml formatting problems (invalid characters) in the
file. However, the Skip() function does not seem to move the cursor
forward and an infinite loop results when an error occurs.


You can't by design. XML spec requires draconian error handling - any
malformed XML document must not be parsed successfully.

--
Oleg Tkachenko [XML MVP, MCAD]
http://blog.tkachenko.com

Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Geoff Bennett | last post by:
While parsing an XML document, my TextReader instance skips nodes. For example, in this fragment: <Person Sex="Male" FirstHomeBuyer="No" YearsInCurrentProfession="14"> <RelatedEntityRef...
2
by: Greg | last post by:
Hi. I have a rather large xml document (object) that can have one or more nodes with a certain attribute throughout (at ANY depth, not at the same level necessarily). I need to find this...
1
by: Emsi | last post by:
Hello, how can I read values of child nodes with the XmlTextReader? File format: <root> <items> <item> <field1>value1</field1> <field2>value2</field2>
1
by: Logician | last post by:
Task: To Read an XML document and handle data contents in .NET for new processing Request: Any details on how to read an XML document processing all nodes and content in .NET Problems:...
1
by: Brent Jenny | last post by:
I have an existing xml file taht looks like this. <?xml version="1.0" encoding="utf-8" ?> <Aircraft> <WCOJOItemType type="AircraftType" > <WCJOItemCode>03</WCJOItemCode>...
1
by: acool | last post by:
If I have an XML file in a string variable what is the best way to go about deleting specific Nodes or elements from this file??
1
by: Christian H | last post by:
Hello! I am currently playing around with XmlTextReader and XmlTextWriter. I've got the TextWriter to write out nodes in this form: <node> <childnode>moredata</childnode> ...
6
by: DWrek | last post by:
Here is my problem. I have an XML document that is returned to me by a third party service. The XML document contains results for a search but only lists a maximum of 10 results. If there are any...
6
by: =?Utf-8?B?VGFtbXkgTmVqYWRpYW4=?= | last post by:
Hi, can someone please let me know how I can read xml elements using object oriented program. I created a class to use the get and set properties however I dont know how I can pass the values from...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.