Re: [xml] problem (bug?) with xmlNewChild()

On Mon, Oct 28, 2002 at 10:19:09AM +0100, Christian Glahn wrote:
Hallo Daniel,
hallo list,

I found an interesting issue in xmlNewChild(). I thought, it is possible
to append a new child to documents, elements and document fragments with 

  Document fragments are a DOM only paradigm. It does not reflect in XML
itself. As a result while it was originally added to the set of node type
the API for this type had nearly zero usage.

xmlNewChild(). It showed that document fragments are not supported by this 
function, although it would make sense to do so.  I concider this as a bug

  I still don't see (except purely for DOM compatibility mode) why this
is useful. I may apply the patch anyway.

If no namespace structure is passed to xmlNewChild() it appears, that the 
namespace of the parent node is silently taken as namespace for the new node
as well. I was quite surprized about this behaviour, since I was expecting a
node with no namespace set. Although the given implementation is unchanged 
at least since 2.4.20, I *think* that's wrong as well.   

  No it's just the semantic of this operation. If you want a different
semantic use a different function, I don;t want to change that now.

Depending on the aspect I mentioned last there are two possible fixes:

/* 1 - my prefered one */
/* tree.c, ~line 2085 */
    if ((parent->type == XML_ELEMENT_NODE) ||
        (parent->type == XML_DOCUMENT_FRAG_NODE)) {
        cur = xmlNewDocNode(parent->doc, ns, name, content);

although in this case a switch statement should be more elegant:

/* 1a */
   switch (parent->type) {
      cur = xmlNewDocNode(parent->doc, ns, name, content);

/* 2 - minimum alternative */
/* tree.c ~line 2095 */
   } else if (parent->type == XML_DOCUMENT_FRAG_NODE) {
      cur = xmlNewDocNode( parent->doc, ns, name, content);
   } else {
/* ... */

  I don't have the time to do this right now. Provide a patch, I will
apply it if it doesn't modify the seamtic of the operation for the other
node types.


Daniel Veillard      | Red Hat Network
veillard redhat com  | libxml GNOME XML XSLT toolkit | Rpmfind RPM search engine

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]