Hi
there is some problem in my application it is unable to add the element in my xml file plzzzzzz help me.
My
java file is
Geography.java ------>
import java.io.File;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
public class GeographyExample {
public static void main (
String argv[]){
try {
File fl=new File("national.xml");
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
Document
doc = docBuilder.parse(fl);
NodeListnl=doc.getElementsByTagName("country");
System.out.println("###########" +nl);
int i = nl.getLength();
for(int j=0 ; j<i;j++){
Node n = nl.item(j);
//Node parent = n.getParentNode();
Element root = doc.createElement("countrythree");
n.appendChild(doc.createTextNode("countrythree"));
System.out.println("----------------->>>>>>>>"+root+ "," +n.appendChild(root)+ "," +n);
}
}catch(Exception e)
{
System.out.println(e);
}
}
}
my xml file is national.xml
<?xml version="1.0" encoding="UTF-8"?>
<geography>
<country>
<countryone>U.S.A</countryone>
<countrytwo>U.K</countrytwo>
</country>
</geography>
i am unable to add <couthrythree> in xml file
plzzzzzzzzz solve it