开发者

xml string to file

开发者 https://www.devze.com 2022-12-14 15:41 出处:网络
I want a xml string to be converted to file,for which i am doing in the below way, String xmlFile=responseXMLName;

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 开发者_Go百科data to this function ,how would i do this?

Document doc = builder.build(...);


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

will do the trick.


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号