smwikipedia
smwikipedia

Reputation: 64173

Question about XmlReader.Read() method

I am confused about the XmlReader.Read() output. Hope someone could explain it.

It seems the XmlReader.Read() method always gives an extra blank line?

Below is my code:

    public static void TestXML()
    {
        XmlReader r = XmlReader.Create(@"d:\snapshot_skeleton.xml");

        //r.MoveToContent();
        while (r.Read())
        {
            Console.Write(new String('.', r.Depth));
            Console.WriteLine(r.Name);
        }
    }

Below is the output:

xml
    <-----------------what is this?
person
.   <-----------------what is this?
.name
..  <-----------------what is this?
.name
.
.gender
..
.gender
.
.age
..
.age
.
person

Upvotes: 0

Views: 118

Answers (1)

Jon
Jon

Reputation: 437326

The empty lines are caused by text nodes, which don't have a Name.

See the table here. Immediately before it is explained:

All other node types return an empty string.

Upvotes: 5

Related Questions