473,386 Members | 1,830 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,386 software developers and data experts.

ReadInnerXml() Seems to Skips a Node

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

<cars007DoesNotDrive>
<car>Chevrolet</car>
<car>Ford</car>
</cars007DoesNotDrive>

I can write this pseudocode fragment:

===========================
string xml = @"<cars007DoesNotDrive>
<car>Chevrolet</car>
<car>Ford</car>
</cars007DoesNotDrive>";

XmlTextReader xmlReader = new XmlTextReader(xml, XmlNodeType.Element, null);

while (xmlReader.Read()
{
xmlReader.MoveToElement();

if (xmlReader.NodeType == XmlNodeType.Element)
{
switch (xmlReader.Name)
{
case "car":
Console.Write(xmlReader.ReadInnerXml());
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:

<cars007DoesNotDrive><car>Chevrolet</car><car>Ford</car></cars007DoesNotDrive>

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 1595

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

Similar topics

0
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...
1
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 () ==...
1
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...
4
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....
1
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...
6
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....
3
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...
2
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...
5
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
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
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,...
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...

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.