WYSIWYG XML Editor java

5.2k Views Asked by At

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?

3

There are 3 best solutions below

1
On BEST ANSWER

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

0
On
  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
0
On

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.