使用解析的XML文档创建JTree

时间:2022-12-07 00:12:20

i want to create a JTree resembling XML dom in java.. below is the XML form...

我想在java中创建一个类似XML dom的JTree ..下面是XML表单...

<html>
  <head>
    <title></title>
    <style></style>
    <body></body>
  </head> 
  <head>
    <title></title>
    <style></style>
    <body></body>
  </head>
</html> 

i want to create this tree structure....

我想创建这个树结构....

2 个解决方案

#1


0  

You can do it easily by parsing the XML and creating a DefaultMutableTreeNode for each XML element. Tree nodes have parents and children just like XML elements so the mapping is easy.

您可以通过解析XML并为每个XML元素创建DefaultMutableTreeNode来轻松完成。树节点具有父元素和子元素,就像XML元素一样,因此映射很容易。

If you set the Element as the user object in DefaultMutableTreeNode you will probably want to provide a custom TreeCellRenderer.

如果在DefaultMutableTreeNode中将Element设置为用户对象,则可能需要提供自定义TreeCellRenderer。

#2


0  

There is a full example here: http://www.cafeconleche.org/books/xmljava/chapters/ch06s05.html

这里有一个完整的例子:http://www.cafeconleche.org/books/xmljava/chapters/ch06s05.html

#1


0  

You can do it easily by parsing the XML and creating a DefaultMutableTreeNode for each XML element. Tree nodes have parents and children just like XML elements so the mapping is easy.

您可以通过解析XML并为每个XML元素创建DefaultMutableTreeNode来轻松完成。树节点具有父元素和子元素,就像XML元素一样,因此映射很容易。

If you set the Element as the user object in DefaultMutableTreeNode you will probably want to provide a custom TreeCellRenderer.

如果在DefaultMutableTreeNode中将Element设置为用户对象,则可能需要提供自定义TreeCellRenderer。

#2


0  

There is a full example here: http://www.cafeconleche.org/books/xmljava/chapters/ch06s05.html

这里有一个完整的例子:http://www.cafeconleche.org/books/xmljava/chapters/ch06s05.html