我有以下代码,使用python和lxml完美地打印文件示例.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习惯用法。这是文件示例.xml我正在使用它:
^{pr2}$
它生成以下输出:
anonymous
1550863090439
anonymous
1550863175384
helloworld
This is just a sample project
{"cq1":{"Source1":{"x":50,"y":-290}}}
这几乎是我想要的,只是我想得到一个子树。我希望能够只得到子树到。如何基于lxml修改上面的Python代码呢?在