Nbl Bz

Nbl Bz

  • NA
  • 56
  • 12.9k

get an XML file with all attributes in a treeview

Oct 9 2014 7:36 AM
Hello ,
am new in C# programmation , then im working on an application for XML  file.
I want to read an XML file on a treeview, i have a code but he dont get all attributes for the node parent  .
this is my function
void BuildNode(XmlNode xmlNode, TreeNode node)
{

if (xmlNode.HasChildNodes)
{


foreach (XmlNode childNode in xmlNode.ChildNodes)
{

var treeNode = new TreeNode(childNode.Name);
node.Nodes.Add(treeNode);
BuildNode(childNode, treeNode);
}


}
else
{
node.Text = (xmlNode.OuterXml).Trim();
}
}
then for my button to browse xml file :
/* var doc = new XmlDocument();
doc.Load(textBox1.Text);
// doc.Load(@"e:\\Test.xml");





treeView1.Nodes.Clear();
var rootNode = new TreeNode(doc.DocumentElement.Name);
treeView1.Nodes.Add(rootNode);
BuildNode(doc.DocumentElement, rootNode);
 



 
treeView1.ExpandAll();


Answers (19)