Solved

DOM java question

Posted on 2006-07-15
2
234 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

Industry Leaders: 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

In this post we will learn different types of Android Layout and some basics of an Android App.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses

631 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