Why does XmlReader skip every other element if there is no whitespace separator? Why does XmlReader skip every other element if there is no whitespace separator? xml xml

Why does XmlReader skip every other element if there is no whitespace separator?


You're calling ReadOuterXml, which will consume the element and place the "cursor" just before the next element. You're then calling Read again, which moves the cursor on (e.g. to the text node within the element).

Here's an alternative to your loop:

while (!xmlReader.EOF){    Console.WriteLine(xmlReader.NodeType);    if (xmlReader.NodeType == XmlNodeType.Element && xmlReader.Name == "bar")    {        var element = xmlReader.ReadOuterXml();        Console.WriteLine("just got an " + element);        count++;                    }    else    {        xmlReader.Read();    }}


Are you perhaps skipping a line by calling the Read() function within the while loop condition and then the ReadOuterXml() function within the loop itself?