Willie B. Hardigan <Wi***************@microsooft.com> wrote:
<snip>
I end up in the case "rnd": for the </rnd> end node for some reason yet when
i change the XML file to this...
<rnd min="0" max="10"/>
with no </rnd> it works fine.
What gives?
XmlTextReader.Name gives the name of the node, which is rnd whether the
node type is element or end element. Nothing strange about that - you
need to change your code to skip over nodes which aren't element nodes.
Here's a quick program which shows you what's going on:
using System;
using System.Xml;
using System.IO;
public class Test
{
static void Main()
{
StringReader sr = new StringReader (
@"<?xml version=""1.0"" encoding=""utf-8"" ?>
<zap>
<data><string>abc</string><hex>a110ff</hex><rnd min=""0""
max=""10""></rnd><string>xyz</string></data>
</zap>");
XmlTextReader xtr = new XmlTextReader(sr);
while (xtr.Read())
{
Console.WriteLine ("{0,-10} {1}", xtr.NodeType, xtr.Name);
}
}
}
It produces output of:
XmlDeclaration xml
Whitespace
Element zap
Whitespace
Element data
Element string
Text
EndElement string
Element hex
Text
EndElement hex
Element rnd
EndElement rnd
Element string
Text
EndElement string
EndElement data
Whitespace
EndElement zap
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too