漂亮的XML(带属性对齐)

时间:2022-09-04 21:44:52

This is a follow-up question to How to pretty print XML from the command line?.

这是如何从命令行中打印XML的后续问题?

Is there any tool in libxml2 that will allow me to align the attributes of each node as well? I have a large XML document whose logical structure I cannot change, but I would like to turn

libxml2中是否有任何工具可以让我对齐每个节点的属性?我有一个大的XML文档,其逻辑结构我无法改变,但我想转向

<a attr="one" bttr="two" tttr="three" fttr="four"/>

into

<a attr   = "one"
   bttr   = "two"
   tttr   = "three"
   fttr   = "four"
   longer = "attribute" />

1 个解决方案

#1


3  

xmllint has an option --pretty which supports three levels of prettyness. If this output:

xmllint有一个选项--pretty,它支持三个级别的漂亮度。如果这个输出:

<?xml version="1.0"?>
<a
    attr="one"
    bttr="two"
    tttr="three"
    fttr="four"
/>

is ok for you, then use --pretty 2 :

对你好,然后使用--pretty 2:

xmllint --pretty 2 - <<< '<a attr="one" bttr="two" tttr="three" fttr="four"/>'

#1


3  

xmllint has an option --pretty which supports three levels of prettyness. If this output:

xmllint有一个选项--pretty,它支持三个级别的漂亮度。如果这个输出:

<?xml version="1.0"?>
<a
    attr="one"
    bttr="two"
    tttr="three"
    fttr="four"
/>

is ok for you, then use --pretty 2 :

对你好,然后使用--pretty 2:

xmllint --pretty 2 - <<< '<a attr="one" bttr="two" tttr="three" fttr="four"/>'