1
public void OpenXmlDoc(string xmlFile)
2
{
3
tvXml.Nodes.Clear();
4
5
//Initailize XML objects
6
XmlTextReader xmlR = new XmlTextReader(xmlFile);
7
XmlDocument xmlDoc = new XmlDocument();
8
xmlDoc.Load(xmlR);
9
xmlR.Close();
10
11
//navigate inside the XLM document & populate the tree
12
TreeNode tnXML = new TreeNode("GUI Test XML");
13
tvXml.Nodes.Add(tnXML);
14
15
XmlNode xnGuiNode = xmlDoc.DocumentElement;
16
XMLRecursion(xnGuiNode, tnXML);
17
18
tvXml.ExpandAll();
19
20
}
21
22
private void XMLRecursion(XmlNode xnGuiNode, TreeNode tnXML)
23
{
24
TreeNode tmpTN = new TreeNode(xnGuiNode.Name + " " + xnGuiNode.Value);
25
26
if (xnGuiNode.Value == "false")
27
{
28
tmpTN.ForeColor = System.Drawing.Color.Red;
29
}
30
31
tnXML.Nodes.Add(tmpTN);
32
33
//preparing recursive call
34
if (xnGuiNode.HasChildNodes)
35
{
36
XmlNode tmpXN = xnGuiNode.FirstChild;
37
while (tmpXN != null)
38
{
39
XMLRecursion(tmpXN, tmpTN);
40
tmpXN = tmpXN.NextSibling;
41
}
42
}
43
}
44
public void OpenXmlDoc(string xmlFile)2
{3
tvXml.Nodes.Clear();4

5
//Initailize XML objects6
XmlTextReader xmlR = new XmlTextReader(xmlFile);7
XmlDocument xmlDoc = new XmlDocument();8
xmlDoc.Load(xmlR);9
xmlR.Close();10

11
//navigate inside the XLM document & populate the tree12
TreeNode tnXML = new TreeNode("GUI Test XML");13
tvXml.Nodes.Add(tnXML);14

15
XmlNode xnGuiNode = xmlDoc.DocumentElement;16
XMLRecursion(xnGuiNode, tnXML);17

18
tvXml.ExpandAll();19
20
}21

22
private void XMLRecursion(XmlNode xnGuiNode, TreeNode tnXML)23
{24
TreeNode tmpTN = new TreeNode(xnGuiNode.Name + " " + xnGuiNode.Value);25

26
if (xnGuiNode.Value == "false")27
{28
tmpTN.ForeColor = System.Drawing.Color.Red;29
}30

31
tnXML.Nodes.Add(tmpTN);32

33
//preparing recursive call 34
if (xnGuiNode.HasChildNodes)35
{36
XmlNode tmpXN = xnGuiNode.FirstChild;37
while (tmpXN != null)38
{39
XMLRecursion(tmpXN, tmpTN);40
tmpXN = tmpXN.NextSibling;41
}42
}43
}44


浙公网安备 33010602011771号