Problem with Elementtree and XMLSchem instance type

Carl Banks pavlovevidence at
Sun Aug 1 06:08:51 CEST 2010

On Jul 30, 6:21 am, Roland Hedberg <roland.hedb... at> wrote:
> Hi!
> I have the following XML snippet:
> <RoleDescriptor
>     xmlns:xsi=""
>     xmlns:fed=""
>     xsi:type="fed:SecurityTokenServiceType">
>     ....
> </RoleDescriptor>
> This part after parsing with Elementtree gives me an Element instance
> with the following properties:
> > tree.tag
> {urn:oasis:names:tc:SAML:2.0:metadata}RoleDescriptor> tree.keys()
> ['{}type']> tree['{}type']
> fed:SecurityTokenServiceType
> And there is the problem, I've lost the coupling between the prefix
> 'fed' and the namespace
> "".
> Is there any way I can get at the prefix <-> namespace mapping from an
> Element instance ?
> I've read the documentation I can find and there is nothing that tells
> me how to get at the mapping.

ElementTree doesn't have a way to do this.

My general feeling is that ElementTree is a lot handier for reading
and writing your own XML formats, than for handling XML files produced
by other tools.

The lxml package has an ElementTree like interface but with some
methods to handle namespace abbreviations.

Carl Banks

More information about the Python-list mailing list