File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes Creating nodes in a document Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Creating nodes in a document" Watch "Creating nodes in a document" New topic

Creating nodes in a document

Guru Vasu

Joined: Nov 11, 2006
Posts: 9


I am new to XML and I am trying to create an xml document.

In java to form the above document I did the following:

After which I am basically stuck - how would I create a node inside the document (I clearly see this is basic and simple) .... but whichever tutorial I go through wont give me an answer for this (there are parsers to read and convert xmls to DOM back and forth - but how would I form just a simple xml

I am expecting something like

I do not want to use external jars/libs/apis like XStream or castor to do the above.

How would I do the above?

thank you
[ November 22, 2006: Message edited by: Guru Vasu ]
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
<root> <element> <name>Name</name> <value>Value</value> </element></root>

Create a document.Create an element with name root and append to document, continue the same to create the structure and for adding Name , create text node and append to element name.

For creating various xml nodes use Document as factory.(it has all the required methods.)

Rahul Bhattacharjee
LinkedIn - Blog
Guru Vasu

Joined: Nov 11, 2006
Posts: 9

Thank you Rahul

The above produced the desired output.

Could you please check and reply if I am doing what you asked me to? and if I can cutshort any of the above calls?

Thank you again Rahul

I agree. Here's the link:
subject: Creating nodes in a document
It's not a secret anymore!