如何利用xml节点的Tags属性来获取其信息和属性?

发布于 2024-07-14 08:19:56 字数 206 浏览 6 评论 0原文

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

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

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

我怎样才能做到这一点?

How would I make use of the Tags property of a node, so that I can get the attributes of an xml node?

I have to display an xml tree in a Windows Form. When I click on any node, its attributes should get displayed on a list box in same form.

I want to make use of tags property, but I need to convert that tree node in the form into an xml node. I wanted to store the tree node in the tag and then typecast that tag to an xml node.

How can I accomplish this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

草莓酥 2024-07-21 08:19:56

添加 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.
...

When adding the TreeNode class, your code would look like this:

// 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.
...

Then when you have the tree view node, you would get the element like this:

TreeNode currentNode = ...;

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

// Process the element.
...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文