manish_regmi
asked on
DOM java question
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(N ODENAME);
int totalTag = listOfTag.getLength();
for(int i=0;i<totalTag;i++)
{
Node fieldNode = listOfTag.item(i);
if(fieldNode.getNodeType() ==Node.ELE MENT_NODE)
{
Element fieldElement = (Element)fieldNode;
NodeList tagList = fieldElement.getElementsBy TagName(co nfigName);
Element tagElement = (Element)tagList.item(0);
NodeList textTList = tagElement.getChildNodes() ;
((Node)textTList.item(0)). setNodeVal ue(data);
System.out.println("Writte n " + data + " reread " + ((Node)textTList.item(0)). getNodeVal ue().trim( ));
break;
}
}
}
The change is only seen in memory but not in file.
Thanks in advance
Manish Regmi
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(N
int totalTag = listOfTag.getLength();
for(int i=0;i<totalTag;i++)
{
Node fieldNode = listOfTag.item(i);
if(fieldNode.getNodeType()
{
Element fieldElement = (Element)fieldNode;
NodeList tagList = fieldElement.getElementsBy
Element tagElement = (Element)tagList.item(0);
NodeList textTList = tagElement.getChildNodes()
((Node)textTList.item(0)).
System.out.println("Writte
break;
}
}
}
The change is only seen in memory but not in file.
Thanks in advance
Manish Regmi
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
regards
Manish Regmi