开发者

Wildcards in getElementsByTagName (xml.dom.minidom)

I'm trying to parse a ODF-document with xml.do开发者_运维百科m.minidom. I would like to get all elements that are text:p OR text:h. Seems like there would be a way to add a wildcard in the getElementsByTagName method. Or is it?

Is there a better way to parse a odf-document without uno?


As getElementsByTagName returns a DOMElement list you could just simply concatenate the two lists.

Alternatively XPath supports and/or operators, so you could use that. That would require using the elementTree or lxml modules instead.


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"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜