c# - how i can use a string that have the same structure how a xml file for a treeview? -
hi how can use string have same structure how xml file treeview. example here part of string coontent..
<?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) 23 hour(s) 0 min(s) 3 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"/> > ....
this string.
i want use string how xml file...can convert string (virtual) xml , fill treeview nodes of feature or user?
my c# code:
private void btnshowlicstate_click(object sender, eventargs e) { string command = "\"c:\\lmxendutil.exe\" -licstatxml -host serv005 -port 6200"; string output = executecommand(command); string final_output = output.substring(90, output.length-90); // here want parse string in xml format string xd , load in treeview txtoutput.text = final_output; } static string executecommand(string command) { int exitcode; processstartinfo processinfo; process process; processinfo = new processstartinfo("cmd.exe", "/c " + command); processinfo.createnowindow = true; processinfo.useshellexecute = false; processinfo.redirectstandarderror = true; processinfo.redirectstandardoutput = true; process = process.start(processinfo); string output = process.standardoutput.readtoend(); exitcode = process.exitcode; process.close(); return output; }
use xdocument class, can create 1 string xdocument.parse(string) or xdocument.load(path).
then use following functions populate tree view (found @ http://social.msdn.microsoft.com/forums/...):
private void buildtree(treeview treeview, xdocument doc) { treenode treenode = new treenode(doc.root.name.localname); treeview.nodes.add(treenode); buildnodes(treenode, doc.root); } private void buildnodes(treenode treenode, xelement element) { foreach (xnode child in element.nodes()) { switch (child.nodetype) { case xmlnodetype.element: xelement childelement = child xelement; treenode childtreenode = new treenode(childelement.name.localname); treenode.nodes.add(childtreenode); buildnodes(childtreenode, childelement); break; case xmlnodetype.text: xtext childtext = child xtext; treenode.nodes.add(new treenode(childtext.value)); break; } } } }
Comments
Post a Comment