Problem with Elementtree and XMLSchem instance type

R

Roland Hedberg

Hi!

I have the following XML snippet:

<RoleDescriptor
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:fed="http://docs.oasis-open.org/wsfed/federation/200706"
xsi:type="fed:SecurityTokenServiceType">
....
</RoleDescriptor>

This part after parsing with Elementtree gives me an Element instance
with the following properties:
tree.tag {urn:eek:asis:names:tc:SAML:2.0:metadata}RoleDescriptor
tree.keys()
['{http://www.w3.org/2001/XMLSchema-instance}type']
tree['{http://www.w3.org/2001/XMLSchema-instance}type']
fed:SecurityTokenServiceType

And there is the problem, I've lost the coupling between the prefix
'fed' and the namespace
"http://docs.oasis-open.org/wsfed/federation/200706".

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.

If I print the Element instance the prefix 'fed' is replace by 'ns0' or
something like that.
Definitely something that has no connection to the original 'fed'.

-- Roland
 
C

Carl Banks

Hi!

I have the following XML snippet:

<RoleDescriptor
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:fed="http://docs.oasis-open.org/wsfed/federation/200706"
    xsi:type="fed:SecurityTokenServiceType">
    ....
</RoleDescriptor>

This part after parsing with Elementtree gives me an Element instance
with the following properties:

{urn:eek:asis:names:tc:SAML:2.0:metadata}RoleDescriptor> tree.keys()

['{http://www.w3.org/2001/XMLSchema-instance}type']> tree['{http://www.w3..org/2001/XMLSchema-instance}type']

fed:SecurityTokenServiceType

And there is the problem, I've lost the coupling between the prefix
'fed' and the namespace
"http://docs.oasis-open.org/wsfed/federation/200706".

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
 
L

Lawrence D'Oliveiro

In message
Carl said:
I said it was not handy, not that is was not useful.

If you want to split hairs, I didn’t say it was “usefulâ€, and I certainly
found it very “handy†for that purpose.
And you don't *have* to try to start an argument over every tiny thing
you disagree with.

What else is USENET for? :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top