我将以下代码与python和lxml结合使用,以漂亮地打印出example.xml文件:
python -c '
from lxml import etree;
from sys import stdout, stdin;
parser=etree.XMLParser(remove_blank_text=True, strip_cdata=False);
tree=etree.parse(stdin, parser)
tree.write(stdout, pretty_print = True)' < example.xml
我使用lxml是因为保留原始文件的保真度(包括保留CDATA习惯用法)非常重要.这是我正在使用的文件example.xml:
anonymous
1550863090439 anonymous
1550863175384 helloworld
This is just a sample project {"cq1":{"Source1":{"x":50,"y":-290}}}
它生成以下输出:
anonymous
1550863090439
anonymous
1550863175384
helloworld
This is just a sample project
{"cq1":{"Source1":{"x":50,"y":-290}}}
这几乎是我想要的,除了我想要一个子树.我希望能够仅获得子树< project name =“ helloworld” ...>通过&l