我们正在将我们古老的FrameMaker文档转换为XML。我的工作是转换:
<?FM MARKER [Index] foo, bar ?>`
为此:
^{pr2}$我不担心这一部分;困扰我的是ProcessingInstruction
遍布文档,并且可能位于任何元素下,所以我需要能够搜索整个树,找到它们,然后处理它们。我不知道如何使用minidom
遍历整个XML树。我缺少一些秘密方法/迭代器吗?到目前为止,我看到的是:
Elementtree
具有优秀的Element.iter()
方法,这是一种深度优先搜索,但它不处理ProcessingInstruction
s。
ProcessingInstruction
没有标记名,因此我无法使用minidom
的getElementsByTagName
来搜索它们。
xml.sax
的ContentHandler.processingInstruction
看起来只用于创建ProcessingInstruction
s。
除了创建我自己的深度优先搜索算法,有没有办法在XML文件中生成ProcessingInstruction
的列表,或者标识它们的父级?在
使用
lxml
模块的XPath API:参考文献
相关问题 更多 >
编程相关推荐