[lxml-dev] iterparse and namespaces

Stefan Behnel stefan_ml at behnel.de
Tue Mar 17 15:13:28 CET 2009


Piotr Furman wrote:
> I've got small problem with iterparse and namespaces. I have this code:
>
>>>> from StringIO import StringIO
>>>> from lxml import etree
>>>> print etree.__version__
> 2.1.5
>>>> xml = """<root
>>>> xmlns="http://www.example.com"><a>1</a><a>2</a></root>"""
>>>> a1 = etree.iterparse(StringIO(xml), tag="a")
>>>> a1.next()
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
>   File "iterparse.pxi", line 515, in lxml.etree.iterparse.__next__
> (src/lxml/lxml.etree.c:77014)
> StopIteration
>>>> a2 = etree.iterparse(StringIO(xml), tag="{http://www.example.com}a")
>>>> a2.next()
> (u'end', <Element {http://www.example.com}a at -488456c4>)
>
> Is that possible to get all tags "a" without passing namespace? I mean, a2
> works, but could it be possible to make a1 working too?

    ..., tag="{*}a"

might work.

Stefan



More information about the lxml-dev mailing list