wood burning stoves 2.0*
The moose likes Java in General and the fly likes generating XML document using Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "generating XML document using Java" Watch "generating XML document using Java" New topic
Author

generating XML document using Java

Varalakshmi Ramanarayan
Ranch Hand

Joined: Oct 28, 2007
Posts: 108
Hi all,

How can I genrate a XML document using Java? What are the imports that I have to use? Also, Please let me know JAXP is helpful in this.
Please Help me with a few examples..

Thanks in advance


SCJP 5 - 87%<br />Next SCWCD
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41077
    
  43
Here's an example of how to create XML using DOM and the JAXP API.


Ping & DNS - my free Android networking tools app
Varalakshmi Ramanarayan
Ranch Hand

Joined: Oct 28, 2007
Posts: 108
Ulf,

This is exaclty what I was looking for.
Thanks very much for your help.

Regards.
Varalakshmi Ramanarayan
Ranch Hand

Joined: Oct 28, 2007
Posts: 108
Ulf,

I have one more problem now . After generating and populating the XML, from other part of my program I need to read the text in each element node.
and i tried using the below code

But on the line marked 'here' I am getting a nullPointer exception (the ele1 is null). For this method I am passing (Document doc,Element root) as the parameters. I am not able to figure out why ele1 is not getting a value.
I am using this code to generete the XML

A sample of my XML document is below.

PLease help me to solve this problem.

Thanks.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41077
    
  43
Could the problem be that the document contains "OptionsIndex" elements, while the code looks for "optionsIndex"?
Varalakshmi Ramanarayan
Ranch Hand

Joined: Oct 28, 2007
Posts: 108
Ulf,

You are right. That was the problem.
I should have looked at the code more carefully.
thanks again for your help.

Regards.
 
jQuery in Action, 2nd edition
 
subject: generating XML document using Java
 
Similar Threads
How to make an XML document into java class using jdom
XML over http
Java way of doing this
Converting String to XML file
Need a java code for convert PDF to Word document as well as Word document to XML. Is this possible