Re: [xml] redicting parts of trees


Von: Rob Richards <rrichards ctindustries net>
Datum: Sun, 22 May 2005 08:25:55 -0400

cazic gmx net wrote:

Yeah, sorry, my example makes no sense; the error was in the first
which should look like this:

 <a2 xmlns:bar="urn:test:OTHER">

with foo bound to "urn:test:mine" initially.

I can see where you get that now. (Note that your closing tag is wrong - 
should be </a1>).

Whoops, sorry again. I'll give a full example this time to avoid further

I had implemented my reconciles a few years back when just starting out 
with the libxml code, so not sure if it is the correct way to do it or 
not, but I reconcile the new appended element - a1 - and not the parent 
element - p - as I did experience what you see and figured passing in 

In my example I reconciled on <a1> as well.

appended element is the correct way to do it.

My output - reconciling on appended element:
<?xml version="1.0"?>
<p xmlns:bar="urn:test:mine"><a1 xmlns:foo="urn:test:mine">
  <a2 xmlns:bar="urn:test:OTHER">
One more thing, can xmlNewReconciliedNs be added to tree.h as its 
currently defined within tree.c?

When adding a single attribute with a namespace, couldn't it be done 
just by:
attr->ns = xmlNewReconciliedNs(attr->doc, attr->parent, attr->ns);

Of course.

rather than having to reconcile the entire parent element, i.e. - 
xmlReconciliateNs(attr->doc, attr->nodep);


The following code:

#include <libxml/tree.h>
#include <libxml/parser.h>

const xmlChar *input = "<?xml version='1.0'?>"
"<foo xmlns:foo='urn:test:mine'>"
"<p xmlns:bar='urn:test:mine'/>"
"<a2 xmlns:bar='urn:test:OTHER'>"

main(int argc, char **argv) {
    xmlDocPtr doc;
    xmlNodePtr node;


    doc = xmlReadDoc(input, NULL, NULL, 0);
    node = doc->children->children->next;
    xmlAddChild(doc->children->children, node);
    xmlReconciliateNs(doc, node);
    xmlDocFormatDump(stdout, doc, 1);

    return (0);

Creates the following output:

<?xml version="1.0"?>
<foo xmlns:foo="urn:test:mine">
  <p xmlns:bar="urn:test:mine">
      <a2 xmlns:bar="urn:test:OTHER">
element a3: error : Reference to namespace 'bar' not in scope

Note that <bar:a3/> is in the wrong namespace now; the shadowed prefix is
detected by the debugXML.c module as well.

But don't bother, I'll fix this during the next days. The drawback will be,
that xmlReconciliateNs will loose performance, since it does currently not
try to check if a namespace is already declared in @tree's decendants. IOW:
it works for a single element-node, but not for a branch.

And: I'll try not to confuse you guys with incomplete examples the next time



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