大家好,我在asp.net 中的treeview 控件有问题。我想用 xml 文件填充它,但 asp.net 中的树视图与窗口窗体树视图控件不同:/
我的树视图的名称是树视图...我在文件夹中没有 xml 我创建了一个 xml 字符串并使用它,但在此示例中我只想测试如何用代码填充此树视图。我怎么能用我的方法做到这一点?
这是我的代码:
XElement doc = XElement.Load("~/App_Data/test_xml.xml");
TreeNode Feature;
TreeNode User;
foreach (XElement state in doc.Descendants("FEATURE"))
{
Feature = treeview.Nodes.Add(state.Attribute("NAME").Value);
foreach (XElement region in state.Descendants("USER"))
{
User =
Feature.Nodes.Add(region.Attribute("NAME").Value);
foreach (XElement area in region.Descendants("NAME"))
{
User.Nodes.Add(area.Attribute("NAME").Value);
}
}
}
我的 xml 示例:
<?xml version="1.0" encoding="UTF-8"?>
<LM-X STAT_VERSION="3.32">
<LICENSE_PATH TYPE="NETWORK" HOST="Server002" SERVER_VERSION="4.4.4" UPTIME="53 day(s) 21 hour(s) 10 min(s) 50 sec(s)">
<FEATURE NAME="GlobalZoneEU" VERSION="12.0" VENDOR="ALTAIR" START="2013-03-26" END="2014-03-31" USED_LICENSES="111720" TOTAL_LICENSES="147000" SHARE="CUSTOM ,VIRTUAL">
<USER NAME="SYSTEM" HOST="Server1" IP="" USED_LICENSES="2000" LOGIN_TIME="2013-04-17 12:42" CHECKOUT_TIME="2013-04-17 12:42" SHARE_CUSTOM=""/>
>
<USER NAME="Admin" HOST="Server1" IP="" USED_LICENSES="720" LOGIN_TIME="2013-04-17 12:44" CHECKOUT_TIME="2013-04-17 12:44" SHARE_CUSTOM=""/>
>
<USER NAME="Test.A" HOST="4327" IP="" USED_LICENSES="21000" LOGIN_TIME="2013-05-21 07:52" CHECKOUT_TIME="2013-05-21 07:52" SHARE_CUSTOM=""/>
>
<USER NAME="Test.B" HOST="4327" IP="" USED_LICENSES="6000" LOGIN_TIME="2013-05-21 07:54" CHECKOUT_TIME="2013-05-21 07:54" SHARE_CUSTOM=""/>
>
<USER NAME="Test.C" HOST="4970" IP="" USED_LICENSES="21000" LOGIN_TIME="2013-05-21 08:15" CHECKOUT_TIME="2013-05-21 08:15" SHARE_CUSTOM=""/>
</FEATURE>
<FEATURE NAME="HWAIFPBS" VERSION="12.0" VENDOR="ALTAIR" START="2013-03-26" END="2014-03-31" USED_LICENSES="0" TOTAL_LICENSES="2147483647" SHARE="CUSTOM ,VIRTUAL"/>
<FEATURE NAME="HWAWPF" VERSION="12.0" VENDOR="ALTAIR" START="2013-03-26" END="2014-03-31" USED_LICENSES="0" TOTAL_LICENSES="2147483647" SHARE="CUSTOM ,VIRTUAL"/>
<FEATURE NAME="HWAcuconsole" VERSION="12.0" VENDOR="ALTAIR" START="2013-03-26" END="2014-03-31" USED_LICENSES="0" TOTAL_LICENSES="2147483647" SHARE="CUSTOM ,VIRTUAL"/>
</LICENSE_PATH>
</LM-X>