0

如何使用节点的 Tags 属性,以便获取 xml 节点的属性?

我必须在 Windows 窗体中显示 xml 树。当我单击任何节点时,它的属性应该以相同的形式显示在列表框中。

我想使用 tags 属性,但我需要将表单中的树节点转换为 xml 节点。我想将树节点存储在标签中,然后将该标签类型转换为 xml 节点。

我怎样才能做到这一点?

4

1 回答 1

1

添加 TreeNode 类时,您的代码将如下所示:

// Create the node.
TreeNode newNode = new TreeNode();

// Configure.
...

// Set the tag property to hold the XML element.
XmlElement currentElement = ...;
newNode.Tag = currentElement;

// Add to the tree view.
...

然后,当您拥有树视图节点时,您将获得如下元素:

TreeNode currentNode = ...;

// Get the XmlElement.
XmlElement currentElement = (XmlElement) currentNode.Tag;

// Process the element.
...
于 2009-03-02T19:34:25.970 回答