467,167 Members | 971 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,167 developers. It's quick & easy.

lxml namespaces problem

Hi All!

I have a little problem with XML namespaces.
In my application I have two XML processors, that process the same
document, one after the other. The first one looks for nodes in 'ns1'
namespace, and substitutes them, according to some algorithm. After
this processor is finished, it is guaranteed that there are no more
'ns1' nodes left in the tree. however 'ns1' namespace dclaration is
still
there, in the root node (well, I put it there manually). Now, when
this namespace is no longer needed, I want to get rid of it, because
it confuses some other processors (namely, my browser)

So, the question is, how do I do that?
del tree.getroot().nsmap['ns1']
does not seem to do the trick :(

Thanks in advance and Happy Holidays!

Jan 7 '07 #1
  • viewed: 3062
Share:
1 Reply
Maxim Sloyko wrote:
I have a little problem with XML namespaces.
In my application I have two XML processors, that process the same
document, one after the other. The first one looks for nodes in 'ns1'
namespace, and substitutes them, according to some algorithm. After
this processor is finished, it is guaranteed that there are no more
'ns1' nodes left in the tree. however 'ns1' namespace dclaration is
still
there, in the root node (well, I put it there manually). Now, when
this namespace is no longer needed, I want to get rid of it, because
it confuses some other processors (namely, my browser)

So, the question is, how do I do that?
del tree.getroot().nsmap['ns1']
does not seem to do the trick :(
Please ask this kind of questions on the lxml mailing list. You might also
want to consider searching the mail archive first.

First of all, lxml produces perfectly well-formed XML here. There is no reason
a document should not contain any unused namespace declarations. It's the
browser that's broken if it handles the namespace incorrectly.

Then: the thing is that lxml can't know that you removed all occurrences of
the respective namespace, so it can't just remove the declaration by itself.
lxml 1.2 will likely be able to handle these things a little (!) more
beautifully, but it's not there yet.

One way to get around this might be to reimplement the namespace replacement
in XSLT. You might also want to try to copy the elements to a newly created
document that does not have the original namespace declaration. Note, however,
that this is not guaranteed to work and might break depending on the lxml version.

Stefan
Jan 8 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Jan Dries | last post: by
30 posts views Thread by Chas Emerick | last post: by
reply views Thread by Stefan Behnel | last post: by
7 posts views Thread by Silfheed | last post: by
1 post views Thread by Owen Zhang | last post: by
2 posts views Thread by jasiu85 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.