0
我需要检索asp.net中的xml属性值。在这里,我不能从XML检索数据。有谁能够帮助我。提前致谢。如何检索asp.net中的xml元素属性名称
我需要检索asp.net中的xml属性值。在这里,我不能从XML检索数据。有谁能够帮助我。提前致谢。如何检索asp.net中的xml元素属性名称
这可能帮助你....
这里是我的XML看起来像:
<?xml version="1.0" encoding="utf-8"?>
<CategoryList>
<Category>
<MainCategory ID="1">VC++</MainCategory>
<Description>A list of VC</Description>
<Active>Yes</Active>
</Category>
</CategoryList>
元素MainCategory的值添加到下拉列表中。我使用SelectNodes
函数获取值并在迭代循环时存储它。看起来像这样:
XmlNodeList nodes = xmlDoc.SelectNodes("/CategoryList/Category");
for(int i=0;i<nodes.Count;i++)
{
ddlMainCategory.Items.Add(new ListItem(
nodes.Item(i).ChildNodes[0].InnerText,
nodes.Item(i).ChildNodes[0].Attributes["ID"].Value
));
}