1

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(...);

2 Answers 2

2
StringReader reader = new StringReader( s );
InputSource inputSource = new InputSource( reader );
Document doc = builder.parse( inputSource );
reader.close();

will do the trick.

Sign up to request clarification or add additional context in comments.

Comments

0

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();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.