Recursive adding XML into TreeView

后端 未结 3 1704
天涯浪人
天涯浪人 2021-01-25 06:56

I\'m trying to import an XML file of nodes into the same node structure in a TreeView using C#. I have found a lot of example that use a single node structure, but have had a lo

3条回答
  •  一生所求
    2021-01-25 07:51

    You are using the wrong variable in your loop over the Classification Elements. Replace groupElement with ClassificationElement inside the loop.

    Change:

    foreach (XElement ClassificationElement in groupElement.Descendants("Classification"))
    {
        // groupElement.Element("ClassificationName") is null:
        treProducts.SelectedNode.Nodes.Add(groupElement.Element("ClassificationName").Value);
        ...
    }
    

    to

    foreach (XElement ClassificationElement in groupElement.Descendants("Classification"))
    {
    treProducts.SelectedNode.Nodes.Add(ClassificationElement.Element("ClassificationName").Value);
        ...
    }
    

提交回复
热议问题