首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

读取xml文件中的text或者value,该怎么解决

2012-01-28 
读取xml文件中的text或者value文件如:武侠传奇text 2 江湖行value 2 测试 /江湖行/武侠传奇

读取xml文件中的text或者value
文件如:
<武侠传奇   text= "2 ">
    <江湖行   value= "2 "> 测试 </江湖行>
</武侠传奇>
................................
使用:
foreach   (TreeNode   node   in   TreeView1.CheckedNodes)
{                        
      str   +=   node.Value.ToString()+   "; ";
      str   +=   node.Text.ToString()   +   " <br> ";
}
读出来得是:
武侠传奇;武侠传奇
.......................................
怎么才能读出来2这个value   值?????

[解决办法]
用XmlAttributeCollection就可以了!
XmlAttributeCollection xmlAttr = xmlNode.Attributes;
for (int i = 0; i < xmlAttr.Count; ++i)
{
if (xmlAttr.Item(i).Name == "武侠传奇 ")
{
this.Url = xmlAttr.Item(i).Value;
break;}
}
[解决办法]
晕死.楼主循环的是treeview.而那是xml应该在绑定的时候把那两个值放在treenode.value中.如:绑定时treeNode.value = xmlNode.Attributes[ "text "].value+ ", "+xmlNode.Attributes[ "value "].value;另外xmlNode.Attributes要先判断是否存在这个属性.

热点排行