问题描述
我需要编写一个基于swing的编辑器,它可以打开指定的xml文件,其中包含我必须在<p>
和</p>之间使用的文本
code> 标签,但文件中还有其他标签.文件中还有其他无用信息,我不需要显示,但需要保留.我只需要显示 JTextComponent
中提到的标签内的文本,让用户修改它并以某种方式将更改写回底层 xml 源.xml 文件中标签的位置会因文件而异,并且一个文件中有多个 <p>
标签,我应该显示所有这些标签的内容并使其可编辑立刻.你怎么认为?完成上述任务的最佳方法是什么?
I need to write a swing based editor that can open specified xml files, which contains the text i have to use between a <p>
and </p>
tag, but there are other tags in the file too. There are other useless informations in the file.I don't need to display them, but it needs to be preserved. I need to dispay only the text inside the mentioned tags in a JTextComponent
and let the user modifying it and somehow write back the changes to the underlying xml source. The positions of the tags in the xml file will vary from file to file and there are more than one <p>
tags in a file, and i should display and make editable the content from all of them at once. What do you think? Which is the best way to accomplish the above task?
推荐答案
如果您想要一个快速的程序化解决方案,只需将您的 XML DOM 读入 JTree.以下是您可以在网上找到的众多示例之一:
If you want a quick'n'dirty programmatic solution, just read your XML DOM into a JTree. Here's one of many, many examples you can find on the web:
http://www.developer.com/xml/article.php/3731356/Displaying-XML-in-a-Swing-JTree.htm
如果您正在寻找开源 XML 编辑器,您可能需要考虑使用 Amaya:
If you're looking for an open source XML editor, you might want to consider Amaya:
附注:您可能知道,Swing 的JTree"实现是最大的 MVC - 您可以轻松地调整任何示例来过滤树模型的内容(即过滤/修改您的 DOM 内容源),或更改外观(即修改您的 JTree 的外观和/或行为).
PS:As you're probably aware, Swing's "JTree" implementation is MVC to the max - you can easily adapt any example to filter the contents of the tree model (i.e. to filter/modify your DOM content source), or to change the appearance (i.e. modify your JTree's appearance and/or behavior).
这篇关于所见即所得 XML 编辑器 java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!