@fzkim , Welcome to Microsoft Q&A, you could try the following code to show all attributes in treeview.
Code:
public void AddNodes(XElement element, TreeNodeCollection parent)
{
var count = element.Elements().Count();
if (count == 0)
{
//var node = parent.Add(element.Name.ToString());
//node.Tag = element;
string attbriutename = "";
if (element.HasAttributes)
{
attbriutename = element.Name.ToString();
foreach (XAttribute att in element.Attributes())
{
attbriutename += " " + att.ToString();
}
}
else
{
attbriutename = element.Name.ToString();
}
var node = parent.Add(attbriutename);
node.Nodes.Add(element.Value);
}
else
{
string attbriutename = "";
if(element.HasAttributes)
{
attbriutename = element.Name.ToString();
foreach (var item in element.Attributes())
{
attbriutename += " "+item.ToString();
}
}
else
{
attbriutename = element.Name.ToString();
}
var node = parent.Add(attbriutename);
//node.Tag = element;
foreach (var child in element.Elements())
{
AddNodes(child, node.Nodes);
}
}
}
Result in xml and treeview:
Best Regards,
Jack
If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.