[lxml-dev] iterparse and namespaces
Stefan Behnel
stefan_ml at behnel.de
Tue Mar 17 16:49:02 CET 2009
Piotr Furman wrote:
> Stefan Behnel <stefan_ml <at> behnel.de> writes:
>> Piotr Furman wrote:
>> > <jholg <at> gmx.de> writes:
>> >> Is there a usecase for "give me every element x from whatever
>> >> namespace"?
>> >
>> > Thanks for answer, my use case is that I have a xml file with only one
>> > namespace
>> > defined in root. I guess that if there were more namespaces in one
>> file it
>> > wouldn't make sense, but as long as it's only one I just don't care
>> about
>> > that and would have all specified elements.
>>
>> uh? Then I really don't get it. If there is only one namespace that
>> contains all elements, then why can't you just look for the tags in
>> exactly that namespace? That will give you all tags with that name.
>>
>> Stefan
>
> Sure I can, but my real data is little bigger than this sample. Each
> element
> found with iterparse has many other tags I'd like to retrieve, using
> "iter"
> method. Here again, for each tag I would have to add namespace. If I do
> this in
> several lines code will be ugly. It would be also harder to maintain, if
> for some reason somebody would change xmlns one day.
>
> So it would be nice if iterparse could accept wildcard as namespace
Note that this would not give you a namespace-free tag name on the
element, so you'd still have to use qualified names in a couple of places.
It's really best to assign the qualified names to variables and to work
with those.
Stefan
More information about the lxml-dev
mailing list