Hi,
I'm testing ElementTree 1.3 a3 and wnat to use the ElementPath to replace the dom getElementsByTagName. After reading and applying the recommendation to resolve {ns}tag into ns_prefix:tag, i try to perform a findall and it doesn't work. i have an element with the following content : <w:pict><v:shape>...</v:shape>....</w:pict>, so i try : myElt.findall('.//v:shape'). It always give me that errors: selector.append(ops[token[0]](next, token))
KeyError: ':' .
I try to debug and find that the xpath_tokenizer is matching ':' as a token, but in this article i do not see the mention of ':' that can be a token.
I don't know if there is a workaround to allow tagname in the form ns_prefix:tag for the xpath support in elementtree. I'm about to migrate from minidom to a pull parser-like api, and want to preserve the tagname i use with the dom. Thanks in advance for any tip.
Roger
If you're using the "prefix:tag" form in XPath expressions in ET 1.3, you need to pass in a dictionary that tells the XPath engine what the prefix means, e.g.
Hi,
I'm testing ElementTree 1.3 a3 and wnat to use the ElementPath to replace the dom getElementsByTagName. After reading and applying the recommendation to resolve {ns}tag into ns_prefix:tag, i try to perform a findall and it doesn't work. i have an element with the following content : <w:pict><v:shape>...</v:shape>....</w:pict>, so i try : myElt.findall('.//v:shape'). It always give me that errors: selector.append(ops[token[0]](next, token))
KeyError: ':' .
I try to debug and find that the xpath_tokenizer is matching ':' as a token, but in this article i do not see the mention of ':' that can be a token.
I don't know if there is a workaround to allow tagname in the form ns_prefix:tag for the xpath support in elementtree. I'm about to migrate from minidom to a pull parser-like api, and want to preserve the tagname i use with the dom. Thanks in advance for any tip.
Roger
If you're using the "prefix:tag" form in XPath expressions in ET 1.3, you need to pass in a dictionary that tells the XPath engine what the prefix means, e.g.
myElt.findall('.//v:shape', {'v': 'http://somethingsomething'})
What prefix the file actually uses is irrelevant.