我正在使用 dom4j 来解析 xml。然后我希望能够将此 xml 表示为 Jtree。每当我通过 dom4j 以编程方式添加或删除节点时,我希望更改立即反映在 Jtree 中。当我单击 Jtree 节点时,如何捕获事件?
我在http://dom4j.sourceforge.net/apidocs/发现了 dom4j.swing 包
但是,我不知道我将如何使用它。我应该使用哪个,我不确定。我似乎找不到这方面的任何示例或教程。
分支树节点、文档树模型、叶树节点。
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
public class Foo {
public Document createDocument() {
Document document = DocumentHelper.createDocument();
Element root = document.addElement( "root" );
Element author1 = root.addElement( "author" )
.addAttribute( "name", "James" )
.addAttribute( "location", "UK" )
.addText( "James Strachan" );
Element author2 = root.addElement( "author" )
.addAttribute( "name", "Bob" )
.addAttribute( "location", "US" )
.addText( "Bob McWhirter" );
return document;
}
}