`
1998a
  • 浏览: 111667 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

code smippet for formatting xml

阅读更多
public static String prettyFormat(String input, int indent) {
    try {
        Source xmlInput = new StreamSource(new StringReader(input));
        StringWriter stringWriter = new StringWriter();
        StreamResult xmlOutput = new StreamResult(stringWriter);
        Transformer transformer = TransformerFactory.newInstance().newTransformer(); 
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", String.valueOf(indent));
        transformer.transform(xmlInput, xmlOutput);
        return xmlOutput.getWriter().toString();
    } catch (Exception e) {
        throw new RuntimeException(e); // simple exception handling, please review it
    }
}

public static String prettyFormat(String input) {
    return prettyFormat(input, 2);
}
 
分享到:
评论

相关推荐

    System.Net.Http.Formatting.xml

    System.Net.Http.Formatting.xml

    Excel: Formatting

    Excel: Formatting Microsoft Excel has many formatting options to make your spreadsheet more attractive and easier to read.

    XML Programming Bible

    Chapter 14: XML Tools for J2EE: IBM, Apache, Sun, and Others . Chapter 15: Xerces . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 16: Xalan . . . . . . . . . . . . . . . . . . . . . . . . ...

    XMLSpy 2011中文版破解补丁

    XML FO (XSL格式化对象:XSL Formatting Objects)说明可视的文档格式化,而 Xpath 则访问XML文档的特定部分。而 XSLT(XSL Transformations)就是把某一XML文档转换为其他格式的实际语言。 XSLT 是什么类型的...

    Teach Yourself XML in 21 Days

    Week Two covers formatting using either CSS or the Extensible Sytlesheet Language, and working with XHTML and other tools for presenting XML data on the Web, or in multimedia applications. The final ...

    Android和XML代码格式化

    window->preferences->java->Code style->Formatter中导入android-formatting.xml 使用方法: 安裝成功后使用快捷鍵:ctrl + shift + f ,Eclipse 自動按照官方要求調整code style XML格式化: ...

    21天学习XML第3版

    Week Two covers formatting using either CSS or the Extensible Sytlesheet Language, and working with XHTML and other tools for presenting XML data on the Web, or in multimedia applications. The final ...

    SQLPrompt_7.3.0.651(包含注册机)

    Fix for incorrectly qualifying a column using the xml "modify" method (Forum post) Fix for syntax error being introduced when wrapping long lines containing multi-line strings 7.3.0.619 - 17th October...

    SQL Assistant v5.0

    While-you-type and standalone code formatters support new formatting options allowing simultaneous use of different cases for keywords and for system functions, for example uppercasing keywords and ...

    Basic Visual Formatting in CSS

    Basic Visual Formatting in CSS

    Jedi Code Format v2.41

    The Jedi Code Formatter is an open-source code formatter for the Borland Delphi Object-Pascal programming language. The formatter can standardise all aspects of Delphi Object Pascal and Delphi.NET ...

    System.Net.Http.Formatting.dll

    System.Net.Http.Formatting.dll

    android eclipse code style

    eclipse开发android,代码标准...1、Preference->Java->Code Style->Formatter->Import->添加android-formatting.xml文件 2、Preference->Java->Code Style->Organize Imports->Import->添加android.importorder文件

    google-java-format

    There is no configurability as to the formatter's algorithm for formatting. This is a deliberate design decision to unify our code formatting on a single format. The formatter can be used in software...

    Devart dbForge Studio for MySQL Professional Edition v7.1.13

    Intelligent code completion, formatting, code snippets bring convenience and effectiveness to your SQL code writing. Code navigation, obtaining quick object information, and syntax check are performed...

    System.Net.Http.Formatting 4.0各版本

    System.Net.Http.Formatting 4.0各版本,asp.net C#.net 都能用到

    serilog-formatting-log4net:以与log4net兼容的XML格式格式化Serilog事件

    Serilog.Formatting.Log4Net是一个附加到格式的日志事件兼容XML格式。 您可以使用查看使用此格式化程序生成的日志文件。 入门 Serilog.Formatting.Log4Net提供了实现Serilog的接口的Log4NetTextFormatter类。 这是...

    System.Net.Http.Formatting

    System.Net.Http.Formatting

    Hack Proofing XML

    The World Wide Web Consortium's Extensible Markup Language (XML) is quickly becoming the new standard for data formatting and Internet development. XML is expected to be as important to the future of ...

    Android Studio实现格式化XML代码顺序

    之前用Eclipse时,格式化XML代码,也会把顺序...File > Settings > Editor > Formatting > Show “Reformat Code” 选项 在XML处格式化代码(默认快捷键是CTRL+ALT+L ,Eclipse是:CTRL+ALT+F) 在弹出 的对话框中勾上Re

Global site tag (gtag.js) - Google Analytics