Assigning root element

i have an existing xml file and i want to append it by adding elements to it.for tht i parsed the xml file and i fot the root node as a string value.but inoder to append its new child i need to assign the string value to a element type.can anyone tell me how to do this.

eg:

String name=doc.getDocumentElement().getNodeName();

this name is my root element.

i need it has a Element type. then only i can append its new child.

thnkx in advance

[478 byte] By [kk_da] at [2007-11-26 23:49:13]
# 1
This is how to add element.Element e = doc.createElement("message");doc.appendChild(e);e.appendChild(doc.createTextNode("hello"));Use XML forum for XML related queries.
baskarka at 2007-7-11 15:25:31 > top of Java-index,Java Essentials,Java Programming...
# 2

but this is not the thing i need.

my xml file is alredy created and i need to add more elements to it.

first i have to parse the xml file and get the root node.im getting it in a string value.

after creating child i need to append it to root.. i ahce created the child but i cant append it bcause the root element is in a string value.i need it as a element type.

can u help me with this

rgds

kk_da at 2007-7-11 15:25:31 > top of Java-index,Java Essentials,Java Programming...
# 3

> ahce created the child but i cant append it bcause

> the root element is in a string value.i need it as a element type.

Try this one.

Element root=doc.getDocumentElement();

This is of Element type. If you want to have the root node name as string, then go for

String val=root.getTagName();

baskarka at 2007-7-11 15:25:31 > top of Java-index,Java Essentials,Java Programming...