tags:

views:

72

answers:

2

Hi All,

I want a xml string to be converted to file,for which i am doing in the below way,

String xmlFile=responseXMLName;
log.info("xml file :" +xmlFile);
fr = new FileWriter(new File(xmlFile));
Writer br= new BufferedWriter(fr); 
log.info("respose string"+responseXMLString);
br.write(responseXMLString);
br.close();

i want to pass xml file data to this function ,how would i do this?

Document doc = builder.build(...);
+1  A: 
StringReader reader = new StringReader( s );
InputSource inputSource = new InputSource( reader );
Document doc = builder.parse( inputSource );
reader.close();

will do the trick.

Brian Agnew
Thank you its good trick
sarah
A: 

If you want a file:

FileWriter fr = null;
try {
  String xmlFile=responseXMLName;
  log.info("xml file :" +xmlFile);
  fr = new FileWriter(xmlFile);
  log.info("respose string"+responseXMLString);
  fr.write(responseXMLString);
} finally {
  if (fr != null) {
      fr.close();
  }
}

To get the document:

StringReader reader = new StringReader( responseXMLString );
InputSource inputSource = new InputSource( reader );
Document doc = builder.parse( inputSource );
reader.close();
Fried Hoeben