By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,345 Members | 1,758 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,345 IT Pros & Developers. It's quick & easy.

lxml namespaces problem

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.