Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

DOM java question

Posted on 2006-07-15
2
Medium Priority
?
237 Views
Last Modified: 2010-03-31
Hi all,

      I am saving my configuration file in XML. I retrieve and update the config file using DOM. I am able to retrieve the data but when i update the valuse changes in memory but not in file.

/* xml file */
<Configuration>
  // Some other stuffs here //
      <Config>
            <ip>192.168.3.120</ip>
            <port>1521</port>
            <database>hitech</database>
      </Config>
</Configuration>

method to update value is like this
       
        static final String NODENAME = "Config";

      public void setConfiguration(String configName, String data)
      {
            NodeList listOfTag = doc.getElementsByTagName(NODENAME);
            int totalTag = listOfTag.getLength();
            for(int i=0;i<totalTag;i++)
            {
                  Node fieldNode = listOfTag.item(i);
                  if(fieldNode.getNodeType()==Node.ELEMENT_NODE)
                  {
                        Element fieldElement = (Element)fieldNode;
                        NodeList tagList = fieldElement.getElementsByTagName(configName);
                        Element tagElement = (Element)tagList.item(0);
                        NodeList textTList = tagElement.getChildNodes();
                        ((Node)textTList.item(0)).setNodeValue(data);
                        System.out.println("Written " + data + " reread " + ((Node)textTList.item(0)).getNodeValue().trim());
                        break;
                  }
            }
      }

The change is only seen in memory but not in file.

Thanks in advance
Manish Regmi
0
Comment
Question by:manish_regmi
2 Comments
 
LVL 92

Accepted Solution

by:
objects earned 2000 total points
ID: 17116582
follwoing example shows how to save it to file

http://javaalmanac.com/egs/javax.xml.transform/WriteDom.html
0
 
LVL 8

Author Comment

by:manish_regmi
ID: 17116600
Thanks it worked.

regards
Manish Regmi
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question