[xml] namespace declaration problems



Hello Daniel,

we are still struggling with the handling of the lifetime
of dyn vars of type xmlNsPtr. (structs, that hold a namespace)

struct xmlNs {
    struct _xmlNs  *next;     /* next Ns link for this node  */
    xmlNsType      type;      /* global or local */
    const xmlChar *href;      /* URL for the namespace */
    const xmlChar *prefix;    /* prefix for the namespace */
};

An XML namespace. Note that prefix == NULL is valid, it defines the
default namespace within the subtree (until overridden).

Variables of this type can be created with xmlNewNs:

xmlNsPtr xmlNewNs    (xmlNodePtr node,
                      const xmlChar *href,
                      const xmlChar *prefix);

but I think, that they are also created automatically by parsing
an xml-file, that containes namespaces, and by cloning nodes with
the param deep.

As far as I understand, they are freed automatically if you free
a document and there is a reference to an xmlNs on one of the 
nsdecl-lists of an element.

If all these assumptions are true, that I have to keep a list 
of the vars of type xmlNsPtr, that are used in orphan nodes, that
are not included in any document tree, and free them manually 
with xmlFreeNs at the end.

Conclusion:

Life would be much easier for us, if libxml2 would keep a list of
namespaces for each document and a list of namespaces, uses by 
orphan nodes (=document fragments or dangeling nodes).
Than it would be possible, to keep the namespaces unique and to free
them as a group, if you don't need them any longer.

Second issue:
-------------

The entries in elem.nsDef:

struct xmlNode {
    void           *_private;   /* application data */
    xmlElementType   type;      /* type number, must be second ! */
    const xmlChar   *name;      /* the name of the node, or the entity */
    struct _xmlNode *children;  /* parent->childs link */
    struct _xmlNode *last;      /* last child link */
    struct _xmlNode *parent;    /* child->parent link */
    struct _xmlNode *next;      /* next sibling link  */
    struct _xmlNode *prev;      /* previous sibling link  */
    struct _xmlDoc  *doc;       /* the containing document */

    /* End of common part */
    xmlNs           *ns;        /* pointer to the associated namespace */
#ifndef XML_USE_BUFFER_CONTENT    
    xmlChar         *content;   /* the content */
#else
    xmlBufferPtr     content;   /* the content in a buffer */
#endif
    struct _xmlAttr *properties;/* properties list */
    xmlNs           *nsDef;     /* namespace definitions on this node */
};

Each element node keeps a list of namespace definitions on it, in the
field nsDef.

What are these entries used for?

As far as I know, they are used for generating the namespace declaration
attributes in the output string, if you export the xml tree to a file.

What else are these entries used for?

Is it important, to keep them up-to-date?

If it is important, than I don't understand, why xmlAddChild doesn't make
any entries in the nsdef list of the parent node.

So, my second feature request:

Could you add this functionality to xmlAddChild, or would it break existing
code?

That's all for now:

Uwe




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