WYSIWYG XML Editor java

一世执手 提交于 2019-12-23 17:39:09

问题


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?


回答1:


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

If you're looking for an open source XML editor, you might want to consider Amaya:

http://www.w3.org/Amaya/

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




回答2:


http://java-sl.com/xml_editor_kit.html You can use the kit as the basis for your project. Add a DocumentFilter to allow editing only the plain text.




回答3:


  1. Load the XML into a DOM tree
  2. Present the required text to the user in your UI
  3. When the user commits changes, update the DOM tree with the new text
  4. Serialize the DOM tree back to XML


来源:https://stackoverflow.com/questions/7984497/wysiwyg-xml-editor-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!