• Post Reply Bookmark Topic Watch Topic
  • New Topic

Editing XML Document - Urgent please  RSS feed

 
Narayanan Jayaraman
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can some one tell me how to open XML document, edit and save that document. I have used jeditorpane and url components. I am able to opend and edit the document. But I don't know how to save back . here is snippets...Thanks.
URL url = null;
String path = null;
try {
path = "/default.xml";
url = aDialogTest.getClass().getResource(path);
if(url != null) {
aDialogTest.ivjJEditorPane1.setPage(url);
}
}
catch (Exception e) {
printError("Failed to open " + path);
url = null;
}
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What XML package are you using? JDOM has XMLOutputter and SAXOutputter. XMLOutputter simply has a method called output() that takes the Document and an OutputStream to write the JDOM tree to an XML file.

If you are just going to use SAX, it is harder, but this tutorial shows you how.
 
Narayanan Jayaraman
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Currently I am not using any XML package. I used only url object to bring/load the XML file in JeditorPane. which isset to Edit mode. Once I click a button (Save) , I would like to write back the changes to the same file. Please see my code. Appreciate your help.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the URL is to an actual file then you would use a File object to save the edited data. Something like the following -

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!