aspose file tools*
The moose likes Java in General and the fly likes How to convert string to xml file in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to convert string to xml file in java" Watch "How to convert string to xml file in java" New topic
Author

How to convert string to xml file in java

vijayakumar durai
Ranch Hand

Joined: Aug 18, 2008
Posts: 153
Hi friends
I am getting the response from webservice as string below content .can anyboy tell how to convert string to xml file in java






Thanks in advance
pawan chopra
Ranch Hand

Joined: Jan 23, 2008
Posts: 410

Try this one :



Pawan Chopra
SCJP - DuMmIeS mInD
Booma Devi
Ranch Hand

Joined: Nov 02, 2011
Posts: 61
}

Exact output should like as below..

[/code][/code]
Saral Saxena
Ranch Hand

Joined: Apr 22, 2011
Posts: 202

pawan chopra wrote:Try this one :



In which drive(C) or drrive (D), it will save the xmlFileName.xml, where you have mentioned that..?
Booma Devi
Ranch Hand

Joined: Nov 02, 2011
Posts: 61
Hi,

I have tried the code which you have suggested... My question is, after converting the xml string to XML file say A.xml...

I want to read the A.XML file and append the data (data is in xml string) to the A.XML file...


Booma Devi
Ranch Hand

Joined: Nov 02, 2011
Posts: 61
I have stored the xml file ( xmlfilename.xml) in different name (I have changed the xml file xmlfilename.xml to books.xml) in my program...

Now, I have another string which contains the XML tags needs to be appended to the existing file books.xml file..

Thanks in Advance...
Booma Devi
Ranch Hand

Joined: Nov 02, 2011
Posts: 61

Hi Saral,

Thanks for your response.. I have found the solution...









Saral Saxena
Ranch Hand

Joined: Apr 22, 2011
Posts: 202

Rt thava wrote:
Hi Saral,

Thanks for your response.. I have found the solution...




HI Rt thava ,

Can you please post your final code here so that we can have a look because one thing that is not clear is that where you have mentioned the path in the code from where it will pick up the college.xml....just like that ...



and where you have mentioned the path of the final xml that is created in which drive and under which directory..!!

It will be graet if you can post your full and final solution that will be a great help..!! thanks in advance..!!
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
Saral Saxena wrote:
Can you please post your final code here so that we can have a look because one thing that is not clear is that where you have mentioned the path in the code from where it will pick up the college.xml....just like that ... ...and where you have mentioned the path of the final xml that is created in which drive and under which directory..!!

The path if not specified will take the folder from where the execution is done. Try below code in your desktop.

Booma Devi
Ranch Hand

Joined: Nov 02, 2011
Posts: 61
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14143
    
  18

If you have the XML in a string, and you want it in a file, then the only thing you have to do is save the string into a file. No need to use the XML parsing API.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Booma Devi
Ranch Hand

Joined: Nov 02, 2011
Posts: 61
Thanks jespar.. :-)
Chathu Dan
Greenhorn

Joined: Mar 09, 2012
Posts: 10
Hopefully you will find the answer here

Create XML using Java DOM



you can find the java source code here Create XML using Java DOM
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18563
    
    8

Arulmozhi Govindaraju,
Your post was moved to a new topic.
Please start a new thread when your question isn't an answer to the thread you considered posting to.
jhessica valdez
Greenhorn

Joined: Feb 01, 2013
Posts: 5
try this code..

import java.io.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;
import org.xml.sax.*;

public class Util {

public static Document stringToDom(String xmlSource)
throws SAXException, ParserConfigurationException, IOException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
return builder.parse(new InputSource(new StringReader(xmlSource)));
}
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to convert string to xml file in java