473,695 Members | 2,810 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

skipping invalid nodes with XmlTextReader

I want to do something like:

bool bContinueReadin g=true;
XmlTextReader Reader=new XmlTextReader(" file.xml");
while(bContinue Reading)
{
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 2833
The code should read:

bool bContinueReadin g=true;
XmlTextReader Reader=new XmlTextReader(" file.xml");
while(bContinue Reading)
{
try
{
bContinueReadin g=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!P LEASEtkachenko. com> wrote in message
news:et******** ******@TK2MSFTN GP10.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
9209
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 RelatedID="118"/> <PersonName> <NameTitle Value="Mr"/> <FirstName>Clint</FirstName> <OtherName/> <AlsoKnownAs>Mr C Eastwood</AlsoKnownAs>
2
10693
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 attribute and remove the containing node (and child nodes) if it has a certain value. I'm able to find the attributes using an XmlTextReader. Once found, can someone help me get the XPath at that point? I would then use this to remove the node from...
1
16427
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
1728
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: Duplicate DATA tags, end nodes (ley01) and then data lower down, system loses its positions My Experience: Handling XML/HTML via Transforms, writing XML using
1
36822
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> <WCJOItemDescription>B737-700</WCJOItemDescription> </WCOJOItemType> </Aircraft> I want to be able to add nodes to the doc using C#. I have tried the
1
1657
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
1897
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> <childnode>moredata</childnode>
6
2721
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 further results then the XML document contains a URL to call and get the next set of 10 results. So if there were 25 results total I would get the first 10 in the first XML document, then after making a second request I would get results 11 to 20...
6
3214
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 xml file to the class and use the values in my form. Thanks -- Nejadian
0
8647
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8585
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9004
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7681
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6504
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4351
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4590
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2285
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1986
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.