字符串生成xml文件

/** * 字符串,生成xml文件 * @param str * @param fileName * @throws IOException */ public void strChangeXML(String str,String fileName ) throws IOException { SAXReader saxReader = new SAXReader(); Document document; try { document = saxReader.read(new ByteArrayInputStream(str.getBytes())); OutputFormat format = OutputFormat.createPrettyPrint(); /** 指定XML字符集编码 */ format.setEncoding("UTF-8"); /** 将document中的内容写入文件中 */ XMLWriter writer = new XMLWriter(new FileWriter(new File(fileName)),format); writer.write(document); writer.close(); } catch (DocumentException e) { // TodoAuto-generatedcatchblock logger.error(e.getMessage()); } }

相关文章

php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念