XML文档:
<?xml version="1.0" encoding="utf-8" ?>
<films>
<directors>
<directors_id>1</directors_id>
<name>hl</name>
<movies>
<movies_id>hl1</movies_id>
<title>yellowroad</title>
<year>1982</year>
</movies>
<movies>
<movies_id>hl2</movies_id>
<title>rain</title>
<year>1983</year>
</movies>
<directors_id>2</directors_id>
<name>tcx</name>
<movies>
<movies_id>tcx1</movies_id>
<title>stairs</title>
<year>2006</year>
</movies>
</directors>
</films>功能部分
protected void Page_Load(object sender, EventArgs e)
{
XmlDocument xd = new XmlDocument();
xd.Load(@"G:\wsn2005\WEB\cs.xml");
XmlReaderSettings xrs = new XmlReaderSettings();
xrs.ConformanceLevel = ConformanceLevel.Auto;
xrs.IgnoreWhitespace = true;
xrs.IgnoreComments = true;
XmlNodeReader xnr = new XmlNodeReader(xd);
XmlReader xr = XmlReader.Create(xnr,xrs);
while(xr.Read())
{
//this.Label1.Text = this.Label1.Text + xr.Value;
//到这时都是执行的,就是下面就不执行了,因为我把上面去掉//后,可以返回值,下面不执行了不知道是为什么
if(xr.NodeType == XmlNodeType.Element)
{
this.Label1.Text = this.Label1.Text+xr.Value;
if (xr.Name == "title")
{
this.Label1.Text = this.Label1.Text + xr.Value;
TreeNode tn = new TreeNode(xr.Value);
this.TreeView1.Nodes.Add(tn);
}
}
}
}在if(xr.NodeType == XmlNodeType.Element)
开始就不执行了不知道是为什么,请大家解决一下
<?xml version="1.0" encoding="utf-8" ?>
<films>
<directors>
<directors_id>1</directors_id>
<name>hl</name>
<movies>
<movies_id>hl1</movies_id>
<title>yellowroad</title>
<year>1982</year>
</movies>
<movies>
<movies_id>hl2</movies_id>
<title>rain</title>
<year>1983</year>
</movies>
<directors_id>2</directors_id>
<name>tcx</name>
<movies>
<movies_id>tcx1</movies_id>
<title>stairs</title>
<year>2006</year>
</movies>
</directors>
</films>功能部分
protected void Page_Load(object sender, EventArgs e)
{
XmlDocument xd = new XmlDocument();
xd.Load(@"G:\wsn2005\WEB\cs.xml");
XmlReaderSettings xrs = new XmlReaderSettings();
xrs.ConformanceLevel = ConformanceLevel.Auto;
xrs.IgnoreWhitespace = true;
xrs.IgnoreComments = true;
XmlNodeReader xnr = new XmlNodeReader(xd);
XmlReader xr = XmlReader.Create(xnr,xrs);
while(xr.Read())
{
//this.Label1.Text = this.Label1.Text + xr.Value;
//到这时都是执行的,就是下面就不执行了,因为我把上面去掉//后,可以返回值,下面不执行了不知道是为什么
if(xr.NodeType == XmlNodeType.Element)
{
this.Label1.Text = this.Label1.Text+xr.Value;
if (xr.Name == "title")
{
this.Label1.Text = this.Label1.Text + xr.Value;
TreeNode tn = new TreeNode(xr.Value);
this.TreeView1.Nodes.Add(tn);
}
}
}
}在if(xr.NodeType == XmlNodeType.Element)
开始就不执行了不知道是为什么,请大家解决一下
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货