简体   繁体   English

getElementsByTagName中的通配符(xml.dom.minidom)

[英]Wildcards in getElementsByTagName (xml.dom.minidom)

I'm trying to parse a ODF-document with xml.dom.minidom. 我正在尝试使用xml.dom.minidom解析ODF文档。 I would like to get all elements that are text:p OR text:h. 我想获取所有为text:p或text:h的元素。 Seems like there would be a way to add a wildcard in the getElementsByTagName method. 似乎有一种方法可以在getElementsByTagName方法中添加通配符。 Or is it? 还是?

Is there a better way to parse a odf-document without uno? 有没有更好的方法来解析odf文档而不需要uno?

As getElementsByTagName returns a DOMElement list you could just simply concatenate the two lists. 当getElementsByTagName返回DOMElement列表时,您只需将两个列表连接即可。

Alternatively XPath supports and/or operators, so you could use that. 另外,XPath支持and/or运算符,因此您可以使用它。 That would require using the elementTree or lxml modules instead. 那将需要改为使用elementTreelxml模块。

root_element.getElementsByTagNameNS('text', '*')

maybe put ? 也许放? instead of * 代替*

this worked for me, but the other way around 这对我有用,但是反过来

<325t4342:Key> fooo </.....>...

key = (root_element.getElementsByTagNameNS('*', "Key")[0]).firstChild.data.strip()

gives me "foo" 给我“ foo”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM