嗨,我在 C# Windows 窗体中遇到了 xml 和树视图控件的问题。
我的应用程序:
首先,我从 cmd 命令创建一个字符串。这是 xml 格式的输出。final_output 是我的 XMLReader 字符串。
字符串命令 = "\"C:\lmxendutil.exe\" -licstatxml -host lwserv005 -port 6200";
string output = ExecuteCommand(command); string final_output = output.Substring(90, output.Length - 90);
其次,我使用 XMLReader 和 StringReader 读取这个字符串并在 xml 中解析它。比我用属性 NAME="..." 的名称为“FEATURE”的所有节点创建一个集合。
XmlReader xr = XmlReader.Create(new StringReader(final_output));
while (xr.Read()) { switch (xr.Name) { case "FEATURE": if (xr.HasAttributes) { while (xr.MoveToNextAttribute()) { if (xr.Name == "NAME") { liste.Add(xr.Value); } } } break; } }
现在我在 TreeView 中显示我的列表。
树节点节点;
foreach (string x in liste) { node = new TreeNode(x); treeLic.Nodes.Add(node); }
XML 结构是这样的:
<FEATURE NAME="" VERSION="" .. >
<USER NAME="" HOST="" ...>
<USER NAME="" HOST="" ...>
<USER NAME="" HOST="" ...>
<FEATURE NAME="" VERSION="" .. >
<FEATURE NAME="" VERSION="" .. >
<FEATURE NAME="" VERSION="" .. >
<USER NAME="" HOST="" ...>
<USER NAME="" HOST="" ...>
<USER NAME="" HOST="" ...>
...
我想用 FEATURE 和 USER 的属性 NAME 值为我的树视图获取这个结构。我的树视图只向我显示具有 NAME 属性值的 FEATURE。我用 readsubtree 尝试它,但它不起作用:(。
我的问题现在...
如何在树视图中显示具有属性 NAME 的所有节点,如果我单击树视图节点,我可以创建一个事件,但我如何使用它来显示有关 FEATURE 节点的子树节点的更多信息?
xml 示例:
<?xml version="1.0" encoding="UTF-8"?>
<LM-X STAT_VERSION="3.32">
<LICENSE_PATH TYPE="NETWORK" HOST="6200@serv005" 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="SERV171" IP="172.16.11.115" USED_LICENSES="2000" LOGIN_TIME="2013-04-17 12:42" CHECKOUT_TIME="2013-04-17 12:42" SHARE_CUSTOM="hweuser:172.16.11.115"/>
>
<USER NAME="pbsadmin" HOST="LWSERV171" IP="172.16.11.115" USED_LICENSES="720" LOGIN_TIME="2013-04-17 12:44" CHECKOUT_TIME="2013-04-17 12:44" SHARE_CUSTOM="pbsadmin:LWSERV171:1592_40960072_1356792762_826820"/>
>
<USER NAME="Bell.M" HOST="DBG4327" IP="172.16.225.105" USED_LICENSES="21000" LOGIN_TIME="2013-05-21 07:52" CHECKOUT_TIME="2013-05-21 07:52" SHARE_CUSTOM="Bell.M:DBG4327"/>
>
<USER NAME="Bell.M" HOST="DBG4327" IP="172.16.225.105" USED_LICENSES="6000" LOGIN_TIME="2013-05-21 07:54" CHECKOUT_TIME="2013-05-21 07:54" SHARE_CUSTOM="Bell.M:DBG4327"/>
>
<USER NAME="xu.d" HOST="DBG4970" IP="172.16.225.126" USED_LICENSES="21000" LOGIN_TIME="2013-05-21 08:15" CHECKOUT_TIME="2013-05-21 08:15" SHARE_CUSTOM="xu.d:DBG4970"/>
>
<USER NAME="xu.d" HOST="DBG4970" IP="172.16.225.126" USED_LICENSES="21000" LOGIN_TIME="2013-05-21 08:18" CHECKOUT_TIME="2013-05-21 08:18" SHARE_CUSTOM="xu.d:DBG4970"/>
>
<USER NAME="Bell.M" HOST="DBG4327" IP="172.16.225.105" USED_LICENSES="21000" LOGIN_TIME="2013-05-21 08:23" CHECKOUT_TIME="2013-05-21 08:23" SHARE_CUSTOM="Bell.M:DBG4327"/>
>
<USER NAME="xu.d" HOST="SIM02" IP="172.16.32.12" USED_LICENSES="21000" LOGIN_TIME="2013-05-21 08:36" CHECKOUT_TIME="2013-05-21 08:36" SHARE_CUSTOM="xu.d:SIM02"/>
>
<USER NAME="xu.d" HOST="SIM02" IP="172.16.32.12" USED_LICENSES="6000" LOGIN_TIME="2013-05-21 08:37" CHECKOUT_TIME="2013-05-21 08:37" SHARE_CUSTOM="xu.d:SIM02"/>
>
<USER NAME="hassan.a" HOST="DBG5199" IP="172.16.225.114" USED_LICENSES="21000" LOGIN_TIME="2013-05-21 09:24" CHECKOUT_TIME="2013-05-21 09:24" SHARE_CUSTOM="hassan.a:DBG5199"/>
>
<USER NAME="xu.d" HOST="SIM02" IP="172.16.32.12" USED_LICENSES="21000" LOGIN_TIME="2013-05-21 09:33" CHECKOUT_TIME="2013-05-21 09:33" SHARE_CUSTOM="xu.d:SIM02"/>
>
<USER NAME="xu.d" HOST="SIM02" IP="172.16.32.12" USED_LICENSES="6000" LOGIN_TIME="2013-05-21 09:33" CHECKOUT_TIME="2013-05-21 09:33" SHARE_CUSTOM="xu.d:SIM02"/>
>
<USER NAME="xu.d" HOST="SIM02" IP="172.16.32.12" USED_LICENSES="2000" LOGIN_TIME="2013-05-21 09:39" CHECKOUT_TIME="2013-05-21 09:39" SHARE_CUSTOM="xu.d:SIM02"/>
>
<USER NAME="zeiser-rasumak.a" HOST="DBG5200" IP="172.16.225.127" USED_LICENSES="21000" LOGIN_TIME="2013-05-21 10:05" CHECKOUT_TIME="2013-05-21 10:05" SHARE_CUSTOM="zeiser-rasumak.a:DBG5200"/>
>
<USER NAME="xu.d" HOST="DBG4970" IP="172.16.225.126" USED_LICENSES="25000" LOGIN_TIME="2013-05-21 10:25" CHECKOUT_TIME="2013-05-21 10:25" SHARE_CUSTOM="xu.d:DBG4970"/>
>
<USER NAME="zeiser-rasumak.a" HOST="DBG5200" IP="172.16.225.127" USED_LICENSES="21000" LOGIN_TIME="2013-05-21 11:27" CHECKOUT_TIME="2013-05-21 11:27" SHARE_CUSTOM="zeiser-rasumak.a:DBG5200"/>
>
<USER NAME="zeiser-rasumak.a" HOST="DBG5200" IP="172.16.225.127" USED_LICENSES="2000" LOGIN_TIME="2013-05-21 11:48" CHECKOUT_TIME="2013-05-21 11:48" SHARE_CUSTOM="zeiser-rasumak.a:DBG5200"/>
>
<USER NAME="zeiser-rasumak.a" HOST="DBG5200" IP="172.16.225.127" USED_LICENSES="21000" LOGIN_TIME="2013-05-21 11:49" CHECKOUT_TIME="2013-05-21 11:49" SHARE_CUSTOM="zeiser-rasumak.a:DBG5200"/>
</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"/>