471,337 Members | 888 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,337 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 1525

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Blaz Lipuscek | last post: by
1 post views Thread by Philipp Schumann | last post: by
1 post views Thread by juli jul | last post: by
1 post views Thread by juli jul | last post: by
6 posts views Thread by VK | last post: by
2 posts views Thread by govolsbaby | last post: by
reply views Thread by rosydwin | last post: by

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.