Solved

DOM java question

Posted on 2006-07-15
2
226 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 500 total points
Comment Utility
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
Comment Utility
Thanks it worked.

regards
Manish Regmi
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
maven java path setting 5 49
What is JNDI datasource in spring 1 36
firstChar challenge 13 83
Free Alternative to JIRA 4 51
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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…
The viewer will learn how to implement Singleton Design Pattern in Java.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now