After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 168764 - xmlCleanupNsDecl()
xmlCleanupNsDecl()
Status: VERIFIED INVALID
Product: libxml2
Classification: Platform
Component: general
2.6.17
Other All
: Normal enhancement
: ---
Assigned To: Daniel Veillard
libxml QA maintainers
Depends on:
Blocks:
 
 
Reported: 2005-02-28 14:36 UTC by Jacek Konieczny
Modified: 2009-08-15 18:40 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Jacek Konieczny 2005-02-28 14:36:53 UTC
I would like to see xmlCleanupNsDecl() function and xmlNode.cleanupNsDecl()
Python method implemented, which would remove unused namespace declaration from
a subtree.

After changing a namespace of an element the namespace prefix (or default
namespace) declaration is still left on the element, even it is not used any
more. It is unneeded and sometime causes real problems — e.g. when default
namespace declared on the element is changed to default namespace of parent
element the serialized XML would be invalid unless xmlReconcilateNs() (which
introduces a new prefix, sill leaving unused declaration) is called.
Unneded namespace declaration may be easily removed using C code, but the
structures are not directly available from Python API, and even if it was
searching for unused declaration in Python would be costly.
Comment 1 Daniel Veillard 2005-02-28 14:50:16 UTC
> which would remove unused namespace declaration from a subtree.
You can't know if a namespace is unused !

<a xmlns:f="http://exampe.org/f" value="f:a"/>

namespaces prefixes may be used in text node content, and you cannot
make any guess about a namespace being unused !

> I would like to see xmlCleanupNsDecl() function and xmlNode.cleanupNsDecl()
> Python method implemented,

  without signature and proper description of the function behaviour I
really can't comment on it, it is hugely undefined in my opinion.

> After changing a namespace of an element the namespace prefix (or default
> namespace) declaration is still left on the element

  Hum, depends how you changed the namespace, if you changed the namespace
pointer yes. If you changed the namespace pointer, i.e. the definition,
then there is no extra namespace. Again this is way too unprecise to be
commented in an intelligent way.

> Unneded namespace declaration may be easily removed using C code

  true assuming you know they are uneeeded. And that property can only 
be decided by the application. In the example above f namespace may be
needed to process the value attribute or not, it all depend on the 
semantic of the instance  and that is application specific.

  At this point you request is not complete and can't be processed as is..

Daniel
  
Comment 2 Jacek Konieczny 2005-02-28 14:59:35 UTC
> without signature and proper description of the function behaviour I
> really can't comment on it, it is hugely undefined in my opinion.

Proposed:

void xmlCleanupNsDecl()(xmlNodePtr tree);

The function would traverse down the tree and find any namespace declarations.
For each declaration it would traverse down the subtree under (and including)
the element with declaration, to see if the namespace is referenced by any
element or attribute there. If it is not, then the declaration would be unlinked
and freed. 

> a xmlns:f="http://exampe.org/f" value="f:a"/>
>
> namespaces prefixes may be used in text node content, and you cannot
> make any guess about a namespace being unused !
[...]
> In the example above f namespace may be
> needed to process the value attribute or not, it all depend on the 
> semantic of the instance  and that is application specific.

By writting "unused" I meant not used in the libxml2 document tree representation.
Comment 3 Jacek Konieczny 2005-02-28 15:00:53 UTC
Here is the mailing list thread describing the problem I encountered which could
be solved using such function:
http://mail.gnome.org/archives/xml/2005-February/msg00123.html
Comment 4 Daniel Veillard 2005-02-28 15:12:02 UTC
As I pointed in the example this is extremely dangerous.
And from an Jabber/xmpp this is even completely wrong ! Example:
Assume you pass an XSLT instance using Jabber, this function
would just wipe out for example the extension namespace
declarations which are needed for the stylesheets but
referenced only as QNames in attribute values ! And XSLt is
just one example, there is a lot of specs rquiring QNames in
attribute values.

The function as you suggest should not be implemented. The
part of "guessing" that a namespace is not used because it's not
referenced by element or attribute descendant is fundamentally wrong
even for the use case you were expecting !

A function removing a *given namespace declaration* on a *given node*
might be defined, but it cannot be made fool-proof, at least it forces
the application to explicitely specify the namespace minimizing the risks.

Daniel

Comment 5 Jacek Konieczny 2005-02-28 19:11:25 UTC
OK, you have convinced me. In fact I need to remove only a known namespace
declaration, which is never used the way you mention. You are right -- in many
circumstances such function could be harmful. However, a function to remove a
given namespace declaration on a given node would be usefull, especially in the
Python API, where it cannot be done directly. But that is another feature
request. I think this one may be closed.
Thanks for explanation.