`
javaz
  • 浏览: 32541 次
  • 性别: Icon_minigender_2
  • 来自: 北京
社区版块
存档分类
最新评论

将xml格式的字符串进行格式化输出

    博客分类:
  • XML
XML 
阅读更多
	public static String formatXml(String str) throws Exception{		
		Document document = null;
		document = DocumentHelper.parseText(str);
		//格式化输出格式
		OutputFormat format = OutputFormat.createPrettyPrint();
		format.setEncoding("gb2312");
		StringWriter writer = new StringWriter();
		//格式化输出流
		XMLWriter xmlWriter = new XMLWriter(writer,format);
		//将document写入到输出流
		xmlWriter.write(document);
		xmlWriter.close();
		//输出到控制台
		System.out.println(writer.toString());
		return writer.toString();
	}

   可根据需要更改编码。

分享到:
评论
1 楼 zht110227 2010-07-21  
编码这个东西不好搞,我这里总是有点小问题。

相关推荐

Global site tag (gtag.js) - Google Analytics