> string xml =
> "<main><textline><textelement>A</textelement><textelement>B</textelement><textelement>C</textelement></textline></main>";
>
> StringReader strReader = new StringReader(xml);
> XmlReader reader = XmlReader.Create(strReader);
> reader.MoveToContent();
Now the reader is positioned on the 'main' start tag.
> int i = 0;
> while (!(reader.NodeType == XmlNodeType.EndElement &&
[quoted text clipped - 9 lines]
> }
> }
For the first run of the loop:
reader.Read() moves reader to the 'textline' start tag.
On the second run of the loop:
reader.Read() moves reader to the 'textelement' start tag.
reader.ReadElementString() moves reader past the 'textelement' end
tag, meaning it is now positioned on the second 'textelement' start tag.
Output: i as 0, text as 'A'.
i set to 1
On the third run of the loop:
reader.Read() moves reader to the text node with contents 'B'.
So there you have the problem, your combination of
Read/ReadElementString and your conditions fail to find the second
'textelement' start tag.
As a solution you might want to use ReadString() instead of
ReadElementString().

Signature
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jan Obrestad - 02 May 2008 07:59 GMT
> As a solution you might want to use ReadString() instead of
> ReadElementString().
That fixed it.
Thank you!
Jan