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();
精彩评论