格式xml,漂亮的打印

Thu*_*fir 6 xml prettify pretty-print

我知道有两种方法可以"漂亮地打印"或格式化xml:

shell工具 Hack 38 Pretty-Print XML使用通用标识样式表和Xalan

有什么其他免费(如啤酒)格式化器?(除了使用javascript)

Nic*_*son 13

好吧,您链接的身份转换可以移植到任何XSLT处理器(Saxon,msxml等).

另外,您可以查看xmllint哪些是LibXML2工具包的一部分.该--format选项允许您打印输入.类似的功能存在于XMLStarlet中(在引擎盖下使用LibXML2).

  • "cat config.xml | xmllint --format - "效果很好. (5认同)
  • 也适用于字符串: `echo "<xml here>" | xmllint --格式-` (2认同)

hen*_*dry 10

xmlstarlet fo是我用于漂亮打印的东西.Xmlstarlet有很多选择:

$ xmlstarlet fo --help
XMLStarlet Toolkit: Format XML document
Usage: xml fo [<options>] <xml-file>
where <options> are
  -n or --noindent            - do not indent
  -t or --indent-tab          - indent output with tabulation
  -s or --indent-spaces <num> - indent output with <num> spaces
  -o or --omit-decl           - omit xml declaration <?xml version="1.0"?>
  -R or --recover             - try to recover what is parsable
  -D or --dropdtd             - remove the DOCTYPE of the input docs
  -C or --nocdata             - replace cdata section with text nodes
  -N or --nsclean             - remove redundant namespace declarations
  -e or --encode <encoding>   - output in the given encoding (utf-8, unicode...)
  -H or --html                - input is HTML
Run Code Online (Sandbox Code Playgroud)

一个优秀的XML工程师应该能够使用xmlstarlet.