开发者

Question about XmlReader.Read() method

开发者 https://www.devze.com 2023-02-19 06:14 出处:网络
I am confused about the XmlReader.Read() output. Hope someone could explain it. It seems the XmlReader.Read() method alwa开发者_JS百科ys gives an extra blank line?

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

It seems the XmlReader.Read() method alwa开发者_JS百科ys 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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消