473,406 Members | 2,549 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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
1 3250
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Jan Dries | last post by:
I'm trying to find Windows binaries for lxml. The cheeseshop is supposed to have such binaries, but I can't find them. Does anyone know where I might find such binaries? Thanks, Jan
30
by: Chas Emerick | last post by:
I looked around for an ElementTree-specific mailing list, but found none -- my apologies if this is too broad a forum for this question. I've been using the lxml variant of the ElementTree API,...
3
by: Dmitri Fedoruk | last post by:
Hello everyone, I'm developing a mod_python application that is based on XML\XSLT transforming. I used 4Suite libraries for that, but as the speed was unacceptable for me, I switched to lxml....
0
by: Stefan Behnel | last post by:
Hi everyone, I'm very happy to announce the official release of lxml 2.0! http://codespeak.net/lxml/ http://pypi.python.org/pypi/lxml/2.0 ** What is lxml? """
7
by: Silfheed | last post by:
Heyas So first off I know that CDATA is generally hated and just shouldn't be done, but I'm simply required to parse it and spit it back out. Parsing is pretty easy with lxml, but it's the...
1
by: =?iso-8859-1?q?KLEIN_St=E9phane?= | last post by:
Hi, I'm on Ubuntu 8.04.1 I've installed lxml with easy_install lxml command. Now, when I load etree I've this error : $ python Python 2.5.2 (r252:60911, Apr 21 2008, 11:12:42)
0
by: =?iso-8859-1?q?KLEIN_St=E9phane?= | last post by:
Le Mon, 25 Aug 2008 13:50:50 +0000, KLEIN Stéphane a écrit : I've this bug only with lxml2, lxml 1.3.3 work very well. Regards, Stephane
1
by: Owen Zhang | last post by:
I am trying to build lxml package in SunOS 5.10. I got the following errors. Does anybody know why? $ python setup.py build Building lxml version 2.1. NOTE: Trying to build without Cython,...
2
by: jasiu85 | last post by:
Hey, I have a problem with character encoding in LXML. Here's how it goes: I read an HTML document from a third-party site. It is supposed to be in UTF-8, but unfortunately from time to time...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.