[lxml-dev] iterparse and namespaces

J. Cliff Dyer jcd at sdf.lonestar.org
Tue Mar 17 16:20:26 CET 2009


On Tue, 2009-03-17 at 14:59 +0000, Piotr Furman wrote:
> <jholg <at> gmx.de> writes:
> > Is there a usecase for "give me every element x from whatever namespace"?
> > 
> > Holger
> 
> 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.
> 
> So I have at least two choices, either remove xmlns from files, or iterate over
> all elements and filter out those I don't need.
> 
> PF
> 

If your concern is that the namespaces are unwieldy, you can also
declare them so that you can use a more readable prefix.

For example (taken from live code):


ns = { 
    'mets': 'http://www.loc.gov/METS/',
    'mods': 'http://www.loc.gov/mods/v3',
}

timestamp_set =
excerpt_filestruct.xpath('mets:fptr[@FILEID="DIGITAL_ACCESS_COPY"]/mets:area', namespaces=ns)

Cheers,
Cliff


> _______________________________________________
> lxml-dev mailing list
> lxml-dev at codespeak.net
> http://codespeak.net/mailman/listinfo/lxml-dev
> 



More information about the lxml-dev mailing list