[New-bugs-announce] [issue28238] In xml.etree.ElementTree findall() can't search all elements in a namespace

py.user report at bugs.python.org
Wed Sep 21 08:38:12 EDT 2016


New submission from py.user:

In the example there are two namespaces in one document, but it is impossible to search all elements only in one namespace:

>>> import xml.etree.ElementTree as etree
>>>
>>> s = '<feed xmlns="http://def" xmlns:x="http://x"><a/><x:b/></feed>'
>>>
>>> root = etree.fromstring(s)
>>>
>>> root.findall('*')
[<Element '{http://def}a' at 0xb73961bc>, <Element '{http://x}b' at 0xb7396c34>]
>>>
>>> root.findall('{http://def}*')
[]
>>>


And same try with site package lxml works fine:

>>> import lxml.etree as etree
>>>
>>> s = '<feed xmlns="http://def" xmlns:x="http://x"><a/><x:b/></feed>'
>>>
>>> root = etree.fromstring(s)
>>>
>>> root.findall('*')
[<Element {http://def}a at 0xb70ab11c>, <Element {http://x}b at 0xb70ab144>]
>>>
>>> root.findall('{http://def}*')
[<Element {http://def}a at 0xb70ab11c>]
>>>

----------
components: Library (Lib), XML
messages: 277130
nosy: py.user
priority: normal
severity: normal
status: open
title: In xml.etree.ElementTree findall() can't search all elements in a namespace
type: behavior
versions: Python 3.6

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue28238>
_______________________________________


More information about the New-bugs-announce mailing list