Reputation: 61
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?
Upvotes: 3
Views: 5358
Reputation: 57381
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.
Upvotes: 3
Reputation: 121629
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:
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).
Upvotes: 4
Reputation: 86764
Upvotes: 2