473,692 Members | 1,925 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ReadInnerXml() Seems to Skips a Node

Let's say I want to loop through the following XML fragment and print
out the "car" values:

<cars007DoesNot Drive>
<car>Chevrole t</car>
<car>Ford</car>
</cars007DoesNotD rive>

I can write this pseudocode fragment:

=============== ============
string xml = @"<cars007DoesN otDrive>
<car>Chevrole t</car>
<car>Ford</car>
</cars007DoesNotD rive>";

XmlTextReader xmlReader = new XmlTextReader(x ml, XmlNodeType.Ele ment, null);

while (xmlReader.Read ()
{
xmlReader.MoveT oElement();

if (xmlReader.Node Type == XmlNodeType.Ele ment)
{
switch (xmlReader.Name )
{
case "car":
Console.Write(x mlReader.ReadIn nerXml());
break;
}

}
}
=============== ==========

This code will work fine given the above XML; that is, it will print out
two values ("Chevrolet" , "Ford") to the console. But suppose, instead,
the XML fragment looks this this:

<cars007DoesNot Drive><car>Chev rolet</car><car>Ford</car></cars007DoesNotD rive>

When I remove the nice formatting, the above code suddenly doesn't not
work. It will instead print out just one value: "Chevrolet, " and skip
"Ford" altogether -- that is, the node following the one where I did a
ReadInnerXml().

I'd sure appreciate some pointers in how to solve this little, vexing
problem.

--Brent
Feb 10 '06 #1
0 1616

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

Similar topics

0
3330
by: Blaz Lipuscek | last post by:
I have a problem with System.Xml.XmlTextReader.ReadInnerXml() Method. By using this method you think it will return a string that contains all child nodes of the current node. I attached a sample xml to this post (bellow) for better understanding. When I use ReadInnerXml method when reader is at <text> element it returns a string : <c>ABC</c>. Up to now everything is ok. It expected that the reader will finish at </text> element, but it...
1
1796
by: Philipp Schumann | last post by:
Hi, I have the following code to copy nodes from an XML document (XmlReader reader) to some output (XmlWriter writer). while (reader.Read ()) if (reader.MoveToContent () == XmlNodeType.Element) break; // forward the reader to the document element writer.WriteStartDocument (false);
1
1884
by: juli jul | last post by:
Hello, I am working with c#. I have a class which reads xml and has to pass to another class(by making an instance of it and activating it constractor) a part of this xml that the next class could read it. I am doing it with ReadInnerXml() but my question is which variable can contain the result of this function in order to pass it as an xml file to the following clas? Thank you very much!
4
6588
by: Prince Kumar | last post by:
I joined a company recently and they have a java program which hangs (does nothing) after a while. This is no way consistent. It could succeed quite a few times and can fail a few other times. There is no consistency when it fails. Could anyone here shed some light on how to debug/resolve the issue. I guess IBM looked at the issue and were not able to pinpoint where the issue is. When the program hangs and when force the DB2...
1
3835
by: juli jul | last post by:
Hello, I have a class which reads xml and has to pass to another class(by making an instance of it and activating it constractor) a part of this xml that the next class could read it. I am doing it with ReadInnerXml() but my question is which variable can contain the result of this function in order to pass it as an xml file to the following clas? Thank you very much!
6
2139
by: VK | last post by:
I must be missing something very obvious, but my nightly head doesn't work anymore. Press "Insert" button to add <insnodes after each <br>. Now press "Delete" - only even <insare being removed. ins.length is reported properly, each <inshas "insert" class name. What a...? <html content="text/html; charset=iso-8859-1"
3
1217
by: vegtard | last post by:
by now, you have no doupt replied to many of mine and my buddy (børntard)'s questions about our faulty programming concerning the over-complicated mega-script to design your dungeons and dragons roleplaying character. well, i think i have cracked it. but theres one slight problem i cant seem to get my head wrapped around. i have an IF-statement in my script. well, i have a rediculous ammount actually. but my script skips one of them, and its...
2
4399
by: govolsbaby | last post by:
Hi All I've got a treeview with checkboxes. I want the user to be able to toggle the checkbox by click on the checkbox OR by clicking on the node text. So I've added an afterselect event handler to get the selected node and change the .Checked property of the selected node as appropriate, which works to change the .Checked status when the user FIRST clicks on the text of a particular node.
5
3579
ram09
by: ram09 | last post by:
I had made a tree view of folders in a rad tree view... I have added a text box with a button in one of my nodes, using this code node.controls.add(txtbox) node.controls.add(btn) where, txtbox is my text box control and btn is my button control... my problem is that I cannot handle the event of the button, when it is already inside the node.. Is there any way I can handle this event?? I already did some customized event for the button...
0
8603
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
8537
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
9081
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8800
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7627
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...
0
5818
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4556
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2236
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1957
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.