我希望将xml字符串转换为文件,我正在以下面的方式进行操作,
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();
我想将xml文件数据传递给此函数,我该怎么做?
Document doc = builder.build(...);
答案 0 :(得分:2)
StringReader reader = new StringReader( s );
InputSource inputSource = new InputSource( reader );
Document doc = builder.parse( inputSource );
reader.close();
会做到这一点。
答案 1 :(得分:0)
如果你想要一个文件:
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();
}
}
获取文件:
StringReader reader = new StringReader( responseXMLString );
InputSource inputSource = new InputSource( reader );
Document doc = builder.parse( inputSource );
reader.close();