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;
}