xml和字符串的转换

2009-07-06 369 0

// 字符串转XMLString xmlStr = "";StringReader sr = new StringReader(xmlStr);InputSource is = new InputSource(sr);DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();DocumentBuilder builder=factory.newDocumentBuilder();Document doc = builder.parse(is);//XML转字符串TransformerFactory tf = TransformerFactory.newInstance();Transformer t = tf.newTransformer();t.setOutputProperty("encoding","utf-8");ByteArrayOutputStream bos = new ByteArrayOutputStream();t.transform(new DOMSource(doc), new StreamResult(bos));String xmlStr = bos.toString();

相关文章

15年来的手艺之路:手艺人赵鹏的自述
纪念 Google 25 周年:从搜索引擎到科技巨头的演变之路
1小时编写一个支持七牛上传的 markdown 客户端3(打包发布篇)
1小时编写一个支持七牛上传的 markdown 客户端2(代码优化篇)
1小时编写一个支持七牛上传的 markdown 客户端1(技术实现篇)
从 wordpress 转移到 hexo

Leave a Reply