Re: [xml] redicting parts of trees
- From: cazic gmx net
- To: Rob Richards <rrichards ctindustries net>
- Cc: xml gnome org
- Subject: Re: [xml] redicting parts of trees
- Date: Sun, 22 May 2005 22:04:24 +0200 (MEST)
Hi,
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
branch,
which should look like this:
<a1>
<a2 xmlns:bar="urn:test:OTHER">
<foo:a3/>
</a2>
</a>
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
confusion.
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">
<foo:a3/>
</a2>
</a1></p>
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);
Rob
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'/>"
"<a1>"
"<a2 xmlns:bar='urn:test:OTHER'>"
"<foo:a3/>"
"</a2>"
"</a1>"
"</foo>";
int
main(int argc, char **argv) {
xmlDocPtr doc;
xmlNodePtr node;
LIBXML_TEST_VERSION
doc = xmlReadDoc(input, NULL, NULL, 0);
node = doc->children->children->next;
xmlUnlinkNode(node);
xmlAddChild(doc->children->children, node);
xmlReconciliateNs(doc, node);
xmlDocFormatDump(stdout, doc, 1);
xmlFreeDoc(doc);
xmlCleanupParser();
return (0);
}
Creates the following output:
P:\libxml2-lab\vs-xml\test1\Debug>test1
<?xml version="1.0"?>
<foo xmlns:foo="urn:test:mine">
<p xmlns:bar="urn:test:mine">
<a1>
<a2 xmlns:bar="urn:test:OTHER">
<bar:a3/>
</a2>
</a1>
</p>
</foo>
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
;-)
Regards,
Kasimier
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]