The Artima Developer Community
Sponsored Link

Java Answers Forum
How do I save my changes to XML file?

2 replies on 1 page. Most recent reply: Sep 12, 2003 2:03 PM by abeselom

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
abeselom

Posts: 4
Nickname: abeselom
Registered: Sep, 2003

How do I save my changes to XML file? Posted: Sep 10, 2003 9:11 AM
Reply to this message Reply
Advertisement
Hi! I read the whole XML document into memory, made the necessary changes using setNodeValue(String). However, this doesn't seem to affect the actual xml file. How do I save my changes to XML file?

The xml doucment is about 10 pages and I am only making change to one node value. Is there a way to output the xml file without looping through createTextNode() for each node.

Thanks!!

Abeselom


Joe Parks

Posts: 107
Nickname: joeparks
Registered: Aug, 2003

Re: How do I save my changes to XML file? Posted: Sep 10, 2003 1:32 PM
Reply to this message Reply
From the JAXP tutorial:
http://java.sun.com/webservices/docs/1.2/tutorial/doc/index.html

DocumentBuilderFactory factory =
          DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse("priceList.xml");
 
 
// Update the document. I.e., setNodeValue(someStringValue)
 
 
TransformerFactory transFactory =
        TransformerFactory.newInstance();
Transformer transformer = transFactory.newTransformer();
DOMSource source = new DOMSource(document);
File newXML = new File("newXML.xml");
FileOutputStream os = new FileOutputStream(newXML);
StreamResult result = new StreamResult(os);
transformer.transform(source, result);

abeselom

Posts: 4
Nickname: abeselom
Registered: Sep, 2003

Re: How do I save my changes to XML file? Posted: Sep 12, 2003 2:03 PM
Reply to this message Reply
Thanks!!!! Its working now.

Flat View: This topic has 2 replies on 1 page
Topic: need for Efficiency tips Previous Topic   Next Topic Topic: Sentence HELP

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use