diff --git a/ChangeLog b/ChangeLog index b909e4dc..72b6dcca 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Sat Feb 5 14:58:46 CET 2005 Daniel Veillard + + * pattern.c: fixed the namespaces support + * tree.c: fixed xmlGetNodePath when namespaces are used + * result/pattern/multiple result/pattern/namespaces + test/pattern/multiple.* test/pattern/namespaces.*: added + more regression tests + Fri Feb 4 18:26:43 CET 2005 Daniel Veillard * xmlschemas.c: fixed one internal function diff --git a/pattern.c b/pattern.c index e9975f76..66452247 100644 --- a/pattern.c +++ b/pattern.c @@ -19,8 +19,6 @@ * currently push(NULL, NULL) means a reset of the streaming context * and indicating we are on / (the document node), probably need * something similar for . - * - xmlPatterncompile support of namespaces arguments, I'm not sure - * it's implemented and definitely not tested * - handling of disjunction "pattern1 | pattern2" mean needed to build * and check a list internally * - get rid of the "compile" starting with lowercase @@ -882,7 +880,6 @@ xmlCompileStepPattern(xmlPatParserContextPtr ctxt) { NEXT; if (CUR != ':') { xmlChar *prefix = name; - xmlNsPtr ns; int i; /* @@ -891,7 +888,7 @@ xmlCompileStepPattern(xmlPatParserContextPtr ctxt) { token = xmlPatScanName(ctxt); for (i = 0;i < ctxt->nb_namespaces;i++) { if (xmlStrEqual(ctxt->namespaces[2 * i + 1], prefix)) { - URL = xmlStrdup(ctxt->namespaces[2 * i + 1]); + URL = xmlStrdup(ctxt->namespaces[2 * i]); break; } } @@ -901,8 +898,6 @@ xmlCompileStepPattern(xmlPatParserContextPtr ctxt) { prefix); ctxt->error = 1; goto error; - } else { - URL = xmlStrdup(ns->href); } xmlFree(prefix); if (token == NULL) { diff --git a/result/pattern/multiple b/result/pattern/multiple new file mode 100644 index 00000000..e10390e1 --- /dev/null +++ b/result/pattern/multiple @@ -0,0 +1,91 @@ +Node /c/b[1]/a[1] matches pattern a +Node /c/b[1]/a[2] matches pattern a +Node /c/c/b/a[1] matches pattern a +Node /c/c/b/a[2] matches pattern a +Node /c/b[2]/a[1] matches pattern a +Node /c/b[2]/a[2] matches pattern a +Node /c/b[1] matches pattern b +Node /c/c/b matches pattern b +Node /c/b[2] matches pattern b +Node /c matches pattern c +Node /c/c matches pattern c +Node /c/b[1] matches pattern c/b +Node /c/c/b matches pattern c/b +Node /c/b[2] matches pattern c/b +Node /c/b[1]/a[1] matches pattern b/a +Node /c/b[1]/a[2] matches pattern b/a +Node /c/c/b/a[1] matches pattern b/a +Node /c/c/b/a[2] matches pattern b/a +Node /c/b[2]/a[1] matches pattern b/a +Node /c/b[2]/a[2] matches pattern b/a +Node /c/b[1]/a[1] matches pattern c/b/a +Node /c/b[1]/a[2] matches pattern c/b/a +Node /c/c/b/a[1] matches pattern c/b/a +Node /c/c/b/a[2] matches pattern c/b/a +Node /c/b[2]/a[1] matches pattern c/b/a +Node /c/b[2]/a[2] matches pattern c/b/a +Node /c/b[1]/a[1] matches pattern c//a +Node /c/b[1]/a[2] matches pattern c//a +Node /c/c/b/a[1] matches pattern c//a +Node /c/c/b/a[2] matches pattern c//a +Node /c/b[2]/a[1] matches pattern c//a +Node /c/b[2]/a[2] matches pattern c//a +Node /c/b[1] matches pattern c//b +Node /c/c/b matches pattern c//b +Node /c/b[2] matches pattern c//b +Node /c/b[1]/a[1] matches pattern b//a +Node /c/b[1]/a[2] matches pattern b//a +Node /c/c/b/a[1] matches pattern b//a +Node /c/c/b/a[2] matches pattern b//a +Node /c/b[2]/a[1] matches pattern b//a +Node /c/b[2]/a[2] matches pattern b//a +Node /c/b[1]/a[1] matches pattern c//b//a +Node /c/b[1]/a[2] matches pattern c//b//a +Node /c/c/b/a[1] matches pattern c//b//a +Node /c/c/b/a[2] matches pattern c//b//a +Node /c/b[2]/a[1] matches pattern c//b//a +Node /c/b[2]/a[2] matches pattern c//b//a +Node /c/b[1]/a[1] matches pattern c/b//a +Node /c/b[1]/a[2] matches pattern c/b//a +Node /c/c/b/a[1] matches pattern c/b//a +Node /c/c/b/a[2] matches pattern c/b//a +Node /c/b[2]/a[1] matches pattern c/b//a +Node /c/b[2]/a[2] matches pattern c/b//a +Node /c/b[1]/a[1] matches pattern c//b/a +Node /c/b[1]/a[2] matches pattern c//b/a +Node /c/c/b/a[1] matches pattern c//b/a +Node /c/c/b/a[2] matches pattern c//b/a +Node /c/b[2]/a[1] matches pattern c//b/a +Node /c/b[2]/a[2] matches pattern c//b/a +Node /c matches pattern /c +Node /c/b[1] matches pattern /c/b +Node /c/b[2] matches pattern /c/b +Node /c/b[1]/a[1] matches pattern /c/b/a +Node /c/b[1]/a[2] matches pattern /c/b/a +Node /c/b[2]/a[1] matches pattern /c/b/a +Node /c/b[2]/a[2] matches pattern /c/b/a +Node /c/b[1]/a[1] matches pattern /c//a +Node /c/b[1]/a[2] matches pattern /c//a +Node /c/c/b/a[1] matches pattern /c//a +Node /c/c/b/a[2] matches pattern /c//a +Node /c/b[2]/a[1] matches pattern /c//a +Node /c/b[2]/a[2] matches pattern /c//a +Node /c/b[1] matches pattern /c//b +Node /c/c/b matches pattern /c//b +Node /c/b[2] matches pattern /c//b +Node /c/b[1]/a[1] matches pattern /c//b//a +Node /c/b[1]/a[2] matches pattern /c//b//a +Node /c/c/b/a[1] matches pattern /c//b//a +Node /c/c/b/a[2] matches pattern /c//b//a +Node /c/b[2]/a[1] matches pattern /c//b//a +Node /c/b[2]/a[2] matches pattern /c//b//a +Node /c/b[1]/a[1] matches pattern /c/b//a +Node /c/b[1]/a[2] matches pattern /c/b//a +Node /c/b[2]/a[1] matches pattern /c/b//a +Node /c/b[2]/a[2] matches pattern /c/b//a +Node /c/b[1]/a[1] matches pattern /c//b/a +Node /c/b[1]/a[2] matches pattern /c//b/a +Node /c/c/b/a[1] matches pattern /c//b/a +Node /c/c/b/a[2] matches pattern /c//b/a +Node /c/b[2]/a[1] matches pattern /c//b/a +Node /c/b[2]/a[2] matches pattern /c//b/a diff --git a/result/pattern/namespaces b/result/pattern/namespaces new file mode 100644 index 00000000..f8b34956 --- /dev/null +++ b/result/pattern/namespaces @@ -0,0 +1,20 @@ +Node /a matches pattern //a +Node /a/b:b/a matches pattern //a +Node /a/a/a matches pattern //a +Node /a/a:a matches pattern //a:a +Node /a/b:b/a/a:a matches pattern //a:a +Node /a/a matches pattern //a:a +Node /a/c:a matches pattern //a:a +Node /a/b matches pattern //b +Node /a/a:a/b:b matches pattern //b:b +Node /a/b:b matches pattern //b:b +Node /a/b:b/a/a:a/b:b matches pattern //b:b +Node /a/b:b/a matches pattern /a//a +Node /a/a/a matches pattern /a//a +Node /a/b matches pattern /a/b +Node /a/a:a matches pattern /a/a:a +Node /a/a matches pattern /a/a:a +Node /a/c:a matches pattern /a/a:a +Node /a/a:a matches pattern /a/c:a +Node /a/a matches pattern /a/c:a +Node /a/c:a matches pattern /a/c:a diff --git a/test/pattern/multiple.pat b/test/pattern/multiple.pat new file mode 100644 index 00000000..3f1ee3e0 --- /dev/null +++ b/test/pattern/multiple.pat @@ -0,0 +1,27 @@ +a +b +c +c/a +c/b +b/a +c/b/a +c//a +c//b +b//a +c//b//a +c/b//a +c//b/a +/a +/b +/c +/c/a +/c/b +/b/a +/c/b/a +/c//a +/c//b +/b//a +/c//b//a +/c/b//a +/c//b/a + diff --git a/test/pattern/multiple.xml b/test/pattern/multiple.xml new file mode 100644 index 00000000..62f31a56 --- /dev/null +++ b/test/pattern/multiple.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/test/pattern/namespaces.pat b/test/pattern/namespaces.pat new file mode 100644 index 00000000..c273a106 --- /dev/null +++ b/test/pattern/namespaces.pat @@ -0,0 +1,10 @@ +//a +//a:a +//b +//b:b +/a//a +/a/a +/a/b +/a/a:a +/a/a:b +/a/c:a diff --git a/test/pattern/namespaces.xml b/test/pattern/namespaces.xml new file mode 100644 index 00000000..1ebb50fa --- /dev/null +++ b/test/pattern/namespaces.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/tree.c b/tree.c index 8ef2fc86..83bf02b1 100644 --- a/tree.c +++ b/tree.c @@ -4307,7 +4307,10 @@ xmlGetNodePath(xmlNodePtr node) tmp = cur->prev; while (tmp != NULL) { if ((tmp->type == XML_ELEMENT_NODE) && - (xmlStrEqual(cur->name, tmp->name))) + (xmlStrEqual(cur->name, tmp->name)) && + ((tmp->ns == cur->ns) || + ((tmp->ns != NULL) && (cur->ns != NULL) && + (xmlStrEqual(cur->ns->prefix, tmp->ns->prefix))))) occur++; tmp = tmp->prev; } @@ -4315,7 +4318,10 @@ xmlGetNodePath(xmlNodePtr node) tmp = cur->next; while (tmp != NULL && occur == 0) { if ((tmp->type == XML_ELEMENT_NODE) && - (xmlStrEqual(cur->name, tmp->name))) + (xmlStrEqual(cur->name, tmp->name)) && + ((tmp->ns == cur->ns) || + ((tmp->ns != NULL) && (cur->ns != NULL) && + (xmlStrEqual(cur->ns->prefix, tmp->ns->prefix))))) occur++; tmp = tmp->next; }