开发者

Wildcards in getElementsByTagName (xml.dom.minidom)

开发者 https://www.devze.com 2023-04-05 02:28 出处:网络
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 getElement

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

精彩评论

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