cancel
Showing results for 
Search instead for 
Did you mean: 

Convert xml to xmldom object

Former Member
0 Kudos

Hi frnds

I need your help as m not a java programmer so m getting a problem in the respective scenario..

I have to write a java program which accept xml as a string and convert xml string to xml dom object, and create a xml file using the xml dom object.

i have done some coding for accepting the xml file and print it on the console that is as like..

import java.io.BufferedReader;

import java.io.File;

import java.io.FileReader;

class XMLConverter

{

public static void main(String args[])

{

String XML_FOLDER_NAME="D:/java/client.xml";

String selectXMLFile="";

try

{

BufferedReader in1 =new BufferedReader(new FileReader(XML_FOLDER_NAME));

String str1 = "";

while ((str1 = in1.readLine()) != null)

{

System.out.println(str1);

}

}

catch (Exception e)

{

System.out.println("Exception: " +e);

}

}

}

But hw to convert xml string to xml dom object and the further evaluation. Plz help me out.

Thnx

Adhir

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

Please check this link. It will be useful.

http://www.brics.dk/~amoeller/XML/programming/domexample.html

Note: http://www.brics.dk/~amoeller/XML/xml/recipes.xml - XML file used by the sample program

Regards,

Dhanasekar K

Reward points if found useful

nitesh_agrawal2
Explorer
0 Kudos

Hi Adhir,

These two links from java.sun.com may help you.

First one is about Reading XML Data into a DOM.

1.http://java.sun.com/webservices/jaxp/dist/1.1/docs/tutorial/dom/1_read.html

Second is about Writing Out a DOM as an XML File

2.http://java.sun.com/webservices/jaxp/dist/1.1/docs/tutorial/xslt/2_write.html

Best Regards,

Nitesh

Former Member
0 Kudos

Hi

Please go through my code snipet in Wiki. To that visit this link

https://www.sdn.sap.com/irj/sdn/wiki?path=/display/java/createDOMObjectfromXMLinJava&

Thanks.

Rajes