Solved

DOM java question

Posted on 2006-07-15
2
233 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 92

Accepted Solution

by:
objects earned 500 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

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
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 …
This video teaches viewers about errors in exception handling.

728 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