• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

How to convert string to xml file in java

 
Ranch Hand
Posts: 153
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 419
Mac jQuery Objective C
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try this one :

 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
}

Exact output should like as below..

[/code][/code]
 
Ranch Hand
Posts: 203
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi Saral,

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









 
Saral Saxena
Ranch Hand
Posts: 203
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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..!!
 
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Booma Devi
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks jespar.. :-)
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 28371
99
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)));
}
}
 
God is a comedian playing for an audience that is afraid to laugh - Voltair. tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic