Display the structure of the XML file with TreeView

xiaoxiao2021-03-06  63

This program is my first role .NET manipulate XML. Its purpose is to display the structure of the XML file with the TreeView control. Please see the following: Private void, TreenodeNode

{

// end recursion if the node is a text type

IF (node ​​== null || node.nodetype == xmlnodetype.text || node.nodetype == xmlnodetype.cdata)

Return;

TreenodeCollection TmptreenodeCollection = addNodetree (Node, ParentNode);

// add all the children of the current node to the treeview

Foreach (XMLnode TmpChildNode in node.childnodes)

{

FillTree (TmpChildNode, TMPTREENODECOLLECTION);

}

}

Private Treenodecollection AddNodeTotree (XMLNode Node, TreenodeCollection ParentNode)

{

Treenode NewChildNode = CreateTreenodeFromXMLNode (Node);

// if Nothing to add, return the parent item

IF (NewChildNode == Null) Return ParentNode;

// add the newly created Tree Node To ITS Parent

IF (parentnode! = null) ParentNode.Add (NewChildNode);

Return NewChildNode.Nodes;

}

Private Treenode CreateTreenodeDefromlnode (XMLNode Node)

{

Treenode Tmptreenode = New Treenode ();

IF (node.haschildnodes) && (node.firstchild.value! = null))

{

TMPTREENODE = New Treenode (Node.Name);

Treenode tmptreenode2 = new treenode (node.firstchild.value);

TMPTREENODE.NODES.ADD (TMPTREENODE2);

}

Else if (node.nodetype! = xmlnodetype.cdata)

{

TMPTREENODE = New Treenode (Node.Name);

}

Return TMPTREENODE;

}

转载请注明原文地址:https://www.9cbs.com/read-111958.html

New Post(0)