when iam trying to create a node in xml file.it is not updating in the xml file.iam sending my sample program.please tellme what is the problem.iam using dom parser with jaxp api.
import org.w3c.dom.*;
import javax.xml.parsers.*;
public class parse1
{
public static void main(
String args[]) {
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse("d://puvvada//book1.xml");
System.out.println("after creatomg xml file");
Node rootNode = document.getDocumentElement();
String s = rootNode.getNodeName();
System.out.println("rootnode=" + s);
NodeList list = document.getElementsByTagName("person");
int length = list.getLength();
System.out.println("length=" + length);
Node temp=null;
Node n1=list.item(1);
Element e=(Element)n1;
System.out.println("hello="+ e.getChildNodes().item(1).getFirstChild().getNodeValue());
System.out.println("la"+e.getChildNodes().item(3).getLastChild().getNodeValue());
System.out.println(e.getChildNodes().item(5).getLastChild().getNodeValue());
Node ndNewColor = document.createElement("color");
ndNewColor.appendChild(document.createTextNode("red"));
catch (Exception e)
{
e.printStackTrace();
}
}
}