Re: [xml] more on recursive xmlCopyNode - patch proposal



Hi,

similar to the strategy used in xmlStaticCopyNode i modified
xmlCopyPropNode, but the case is not that simple.

Unfortunately i make use of xmlNewReconciliedNs when everything else
fails. More unfortunately xmlNewReconciliedNs has a Bug:

xmlNewReconciliedNs makes use of xmlSearchNsByHref and returns if
a namespace is found. That is wrong: You cant be sure that the
prefix found by xmlSearchNsByHref is not rebound on the path from
the carrying node down to @tree. Thus xmlNewReconciliedNs needs fixing
to make this patch heal xmlCopyProp.

Nevertheless here it is. Its untested!!!

Boris

---------------------------------------------------------------------
2822c2822
<
---
>
2825,2831c2825,2873
<       if (target->doc)
<    ns = xmlSearchNs(target->doc, target, cur->ns->prefix);
<       else if (cur->doc)  /* target may not yet have a doc : KPI */
<    ns = xmlSearchNs(cur->doc, target, cur->ns->prefix);
<       else
<    ns = NULL;
<    ret->ns = ns;
---
> /*
>  *      if (target->doc)
>  * ns = xmlSearchNs(target->doc, target, cur->ns->prefix);
>  *      else if (cur->doc)  / * target may not yet have a doc : KPI * /
>  * ns = xmlSearchNs(cur->doc, target, cur->ns->prefix);
>  *      else
>  * ns = NULL;
>  * ret->ns = ns;
>  */
>       ns = xmlSearchNs(target->doc, target, cur->ns->prefix);
>       if (ns == NULL) {
>         /*
>          * Humm, we are copying an element whose namespace is defined
>          * out of the new tree scope. Search it in the original tree
>          * and add it at the top of the new tree
>          */
>         ns = xmlSearchNs(cur->doc, cur->parent, cur->ns->prefix);
>         if (ns != NULL) {
>           xmlNodePtr root = target;
>           xmlNodePtr pred = NULL;
>
>           while (root->parent != NULL) {
>             pred = root;
>             root = root->parent;
>           }
>           if (root == (xmlNodePtr) target->doc) {
>             /* correct possibly cycling above the document elt */
>             root = pred;
>           }
>           ret->ns = xmlNewNs(root, ns->href, ns->prefix);
>         }
>       } else {
>         /*
>          * we have to find something appropriate here since
>          * we cant be sure, that the namespce we found is identified
>          * by the prefix
>          */
>         if (xmlStrEqual(ns->href, ret->ns->href)) {
>           /* this is the nice case */
>           ret->ns = ns;
>         } else {
>           /*
>            * we are in trouble: we need a new reconcilied namespace.
>            * This is expensive
>            */
>           ret->ns = xmlNewReconciliedNs(target->doc, target, cur->ns);
>         }
>       }
>




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