using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
namespace _122
{
public class test
{
public void ReadFromFile()
{
string sf = "..\\..\\test.xml";
XmlTextReader xr = new XmlTextReader(sf);
xr.WhitespaceHandling = WhitespaceHandling.None;
while(xr.Read())
{
for(int i = 0;i < xr.Depth;i++)
Console.Write("\t");
switch(xr.NodeType)
{
case XmlNodeType.Element:
Console.WriteLine("<{0}>",xr.Name);
break;
case XmlNodeType.Text:
Console.WriteLine("<{0}>",xr.Value);
break;
}
}
if(xr != null)
xr.Close();
}
static void Main(string[] args)
{
test obj = new test();
obj.ReadFromFile();
}
}
}
这段代码运行是提示"while(xr.Read())"这行无效