From c8df0aaf9f8912e66c4d5050dd2e1df1a3f482b2 Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Tue, 10 Oct 2000 23:50:30 +0000 Subject: [PATCH] Added XPointer: - configure.in Makefile.am include/makefile.am: adding Added XPointer: - configure.in Makefile.am include/makefile.am: adding XPointer and XPtrtests target - xpointer.[ch] : new files for XPointer support - test/XPath/xptr result/XPath/xptr: added XPointer testsuite and more XPath tests Daniel --- ChangeLog | 8 +++++ Makefile.am | 27 ++++++++++++++++- configure.in | 12 ++++++++ include/Makefile.am | 1 + include/libxml/xmlversion.h.in | 9 ++++++ result/XPath/tests/chaptersbase | 30 +++++++++++++++++++ result/XPath/tests/chaptersprefol | 24 +++++++++++++++ result/XPath/tests/vidbase | 42 ++++++++++++++++++++++++++ result/XPath/xptr/chapterschildseq | 14 +++++++++ result/XPath/xptr/chaptersparts | 44 +++++++++++++++++++++++++++ result/XPath/xptr/chaptersrange | 48 ++++++++++++++++++++++++++++++ result/XPath/xptr/vidbase | 19 ++++++++++++ result/XPath/xptr/vidchildseq | 18 +++++++++++ result/XPath/xptr/vidparts | 27 +++++++++++++++++ test/XPath/docs/vid | 43 ++++++++++++++++++++++++++ test/XPath/tests/vidbase | 5 ++++ test/XPath/xptr/chapterschildseq | 2 ++ test/XPath/xptr/chaptersparts | 6 ++++ test/XPath/xptr/chaptersrange | 3 ++ test/XPath/xptr/vidbase | 2 ++ test/XPath/xptr/vidchildseq | 2 ++ test/XPath/xptr/vidparts | 3 ++ xmlversion.h.in | 9 ++++++ xpath.c | 25 ++++++++++++++-- 24 files changed, 419 insertions(+), 4 deletions(-) create mode 100644 result/XPath/tests/vidbase create mode 100644 result/XPath/xptr/chapterschildseq create mode 100644 result/XPath/xptr/chaptersparts create mode 100644 result/XPath/xptr/chaptersrange create mode 100644 result/XPath/xptr/vidbase create mode 100644 result/XPath/xptr/vidchildseq create mode 100644 result/XPath/xptr/vidparts create mode 100644 test/XPath/docs/vid create mode 100644 test/XPath/tests/vidbase create mode 100644 test/XPath/xptr/chapterschildseq create mode 100644 test/XPath/xptr/chaptersparts create mode 100644 test/XPath/xptr/chaptersrange create mode 100644 test/XPath/xptr/vidbase create mode 100644 test/XPath/xptr/vidchildseq create mode 100644 test/XPath/xptr/vidparts diff --git a/ChangeLog b/ChangeLog index 50dfe932..a729636e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Wed Oct 11 01:46:44 CEST 2000 Daniel Veillard + + * configure.in Makefile.am include/makefile.am: adding XPointer + and XPtrtests target + * xpointer.[ch] : new files for XPointer support + * test/XPath/xptr result/XPath/xptr: added XPointer testsuite and + more XPath tests + Wed Oct 11 01:23:25 CEST 2000 Daniel Veillard * configure.in: fixed, very broken, make distcheck works again diff --git a/Makefile.am b/Makefile.am index e0ae8607..4fe98824 100644 --- a/Makefile.am +++ b/Makefile.am @@ -32,6 +32,7 @@ libxml_la_SOURCES = \ HTMLtree.c \ debugXML.c \ xpath.c \ + xpointer.c \ nanohttp.c \ nanoftp.c @@ -79,7 +80,7 @@ $(libxml_la_SOURCES): $(srcdir)/libxml testall : tests SVGtests SAXtests -tests: XMLtests XMLenttests HTMLtests Validtests URItests XPathtests +tests: XMLtests XMLenttests HTMLtests Validtests URItests XPathtests XPtrtests HTMLtests : testHTML @(rm -f .memdump ; touch .memdump) @@ -234,6 +235,7 @@ XPathtests : testXPath if [ ! -d $$i ] ; then \ doc=`basename $$i`; \ for j in $(srcdir)/test/XPath/tests/$$doc* ; do \ + if [ ! -f $$j ] ; then continue ; fi ; \ name=`basename $$j`; \ if [ ! -d $$j ] ; then \ if [ ! -f $(srcdir)/result/XPath/tests/$$name ] ; then \ @@ -246,6 +248,29 @@ XPathtests : testXPath rm result.$$name ; \ fi ; fi ; done ; fi ; done) +XPtrtests : testXPath + @(rm -f .memdump ; touch .memdump) + @echo "##" + @echo "## XPointer regression tests" + @echo "##" + @(for i in $(srcdir)/test/XPath/docs/* ; do \ + if [ ! -d $$i ] ; then \ + doc=`basename $$i`; \ + for j in $(srcdir)/test/XPath/xptr/$$doc* ; do \ + if [ ! -f $$j ] ; then continue ; fi ; \ + name=`basename $$j`; \ + if [ ! -d $$j ] ; then \ + if [ ! -f $(srcdir)/result/XPath/xptr/$$name ] ; then \ + echo New test file $$name ; \ + ./testXPath -xptr -f -i $$i $$j > $(srcdir)/result/XPath/xptr/$$name ; \ + else \ + echo Testing $$name ; \ + ./testXPath -xptr -f -i $$i $$j > result.$$name ; \ + grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0";\ + diff $(srcdir)/result/XPath/xptr/$$name result.$$name ; \ + rm result.$$name ; \ + fi ; fi ; done ; fi ; done) + SVGtests : xmllint @echo "##" @echo "## SVG parsing regression tests" diff --git a/configure.in b/configure.in index 7cac90f8..28b4685e 100644 --- a/configure.in +++ b/configure.in @@ -245,6 +245,18 @@ fi AC_SUBST(WITH_XPATH) AC_SUBST(XPATH_OBJ) +AC_ARG_WITH(xptr, [ --with-xptr Add the XPointer support (on)]) +if test "$with_xptr" = "no" ; then + echo Disabling XPointer support + WITH_XPTR=0 + XPTR_OBJ= +else + WITH_XPTR=1 + XPTR_OBJ=xpointer.o +fi +AC_SUBST(WITH_XPTR) +AC_SUBST(XPTR_OBJ) + AC_ARG_WITH(iconv, [ --with-iconv Add the ICONV support (on)]) if test "$with_iconv" = "no" ; then echo Disabling ICONV support diff --git a/include/Makefile.am b/include/Makefile.am index eea4e9cb..e2375fe8 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -15,6 +15,7 @@ xmlinc_HEADERS = \ libxml/debugXML.h \ libxml/tree.h \ libxml/xpath.h \ + libxml/xpointer.h \ libxml/xmlIO.h \ libxml/xmlmemory.h \ libxml/nanohttp.h \ diff --git a/include/libxml/xmlversion.h.in b/include/libxml/xmlversion.h.in index 6b41be44..ed1c43fd 100644 --- a/include/libxml/xmlversion.h.in +++ b/include/libxml/xmlversion.h.in @@ -77,6 +77,15 @@ extern void xmlCheckVersion(int version); #define LIBXML_XPATH_DISABLED #endif +/* + * Whether XPointer is configured in + */ +#if @WITH_XPTR@ +#define LIBXML_XPTR_ENABLED +#else +#define LIBXML_XPTR_DISABLED +#endif + /* * Whether iconv support is available */ diff --git a/result/XPath/tests/chaptersbase b/result/XPath/tests/chaptersbase index b004efe3..fd4040e4 100644 --- a/result/XPath/tests/chaptersbase +++ b/result/XPath/tests/chaptersbase @@ -35,10 +35,25 @@ Object is a Node Set : Set contains 6 nodes: 1 ELEMENT head 2 ELEMENT chapter + ATTRIBUTE id + TEXT + content=chapter1 3 ELEMENT chapter + ATTRIBUTE id + TEXT + content=chapter2 4 ELEMENT chapter + ATTRIBUTE id + TEXT + content=chapter3 5 ELEMENT chapter + ATTRIBUTE id + TEXT + content=chapter4 6 ELEMENT chapter + ATTRIBUTE id + TEXT + content=chapter5 ======================== Expression: /child::EXAMPLE/child::head/child::title @@ -75,7 +90,22 @@ Expression: /descendant::p/ancestor::chapter Object is a Node Set : Set contains 5 nodes: 1 ELEMENT chapter + ATTRIBUTE id + TEXT + content=chapter1 2 ELEMENT chapter + ATTRIBUTE id + TEXT + content=chapter2 3 ELEMENT chapter + ATTRIBUTE id + TEXT + content=chapter3 4 ELEMENT chapter + ATTRIBUTE id + TEXT + content=chapter4 5 ELEMENT chapter + ATTRIBUTE id + TEXT + content=chapter5 diff --git a/result/XPath/tests/chaptersprefol b/result/XPath/tests/chaptersprefol index 930bb7ab..6222eed9 100644 --- a/result/XPath/tests/chaptersprefol +++ b/result/XPath/tests/chaptersprefol @@ -26,6 +26,9 @@ Set contains 10 nodes: 1 ELEMENT p 2 ELEMENT title 3 ELEMENT chapter + ATTRIBUTE id + TEXT + content=chapter2 4 ELEMENT p 5 ELEMENT image ATTRIBUTE href @@ -34,6 +37,9 @@ Set contains 10 nodes: 6 ELEMENT p 7 ELEMENT title 8 ELEMENT chapter + ATTRIBUTE id + TEXT + content=chapter1 9 ELEMENT title 10 ELEMENT head @@ -42,9 +48,15 @@ Expression: /child::EXAMPLE/child::chapter[3]/following::* Object is a Node Set : Set contains 6 nodes: 1 ELEMENT chapter + ATTRIBUTE id + TEXT + content=chapter4 2 ELEMENT title 3 ELEMENT p 4 ELEMENT chapter + ATTRIBUTE id + TEXT + content=chapter5 5 ELEMENT title 6 ELEMENT p @@ -63,14 +75,26 @@ Object is a Node Set : Set contains 13 nodes: 1 ELEMENT p 2 ELEMENT chapter + ATTRIBUTE id + TEXT + content=chapter2 3 ELEMENT title 4 ELEMENT p 5 ELEMENT chapter + ATTRIBUTE id + TEXT + content=chapter3 6 ELEMENT title 7 ELEMENT p 8 ELEMENT chapter + ATTRIBUTE id + TEXT + content=chapter4 9 ELEMENT title 10 ELEMENT p 11 ELEMENT chapter + ATTRIBUTE id + TEXT + content=chapter5 12 ELEMENT title 13 ELEMENT p diff --git a/result/XPath/tests/vidbase b/result/XPath/tests/vidbase new file mode 100644 index 00000000..3c7b62fb --- /dev/null +++ b/result/XPath/tests/vidbase @@ -0,0 +1,42 @@ + +======================== +Expression: id('chapter1') +Object is a Node Set : +Set contains 1 nodes: +1 ELEMENT chapter + ATTRIBUTE id + TEXT + content=chapter1 + +======================== +Expression: id('chapter3') +Object is a Node Set : +Set contains 1 nodes: +1 ELEMENT chapter + ATTRIBUTE id + TEXT + content=chapter3 + +======================== +Expression: id('chapter1')/p +Object is a Node Set : +Set contains 4 nodes: +1 ELEMENT p +2 ELEMENT p +3 ELEMENT p +4 ELEMENT p + +======================== +Expression: id('chapter1')//p +Object is a Node Set : +Set contains 4 nodes: +1 ELEMENT p +2 ELEMENT p +3 ELEMENT p +4 ELEMENT p + +======================== +Expression: id('chapter1')/p[1] +Object is a Node Set : +Set contains 1 nodes: +1 ELEMENT p diff --git a/result/XPath/xptr/chapterschildseq b/result/XPath/xptr/chapterschildseq new file mode 100644 index 00000000..ef49ee50 --- /dev/null +++ b/result/XPath/xptr/chapterschildseq @@ -0,0 +1,14 @@ + +======================== +Expression: /1/2/3 +Object is a Node Set : +Set contains 1 nodes: +1 ELEMENT image + ATTRIBUTE href + TEXT + content=linus.gif + +======================== +Expression: chapter1/3 +Object is a Node Set : +Set contains 0 nodes: diff --git a/result/XPath/xptr/chaptersparts b/result/XPath/xptr/chaptersparts new file mode 100644 index 00000000..70b561b3 --- /dev/null +++ b/result/XPath/xptr/chaptersparts @@ -0,0 +1,44 @@ + +======================== +Expression: xpointer(//chapitre[2]) +Object is empty (NULL) + +======================== +Expression: xpointer(//chapter[2]) +Object is a Node Set : +Set contains 1 nodes: +1 ELEMENT chapter + ATTRIBUTE id + TEXT + content=chapter2 + +======================== +Expression: xpointer(//chapitre[2])xpointer(//chapter[2]) +Object is a Node Set : +Set contains 1 nodes: +1 ELEMENT chapter + ATTRIBUTE id + TEXT + content=chapter2 + +======================== +Expression: xpointer(id("chapter1")) +Object is empty (NULL) + +======================== +Expression: xpointer(//*[@id="chapter1"]) +Object is a Node Set : +Set contains 1 nodes: +1 ELEMENT chapter + ATTRIBUTE id + TEXT + content=chapter1 + +======================== +Expression: xpointer(id("chapter1"))xpointer(//*[@id="chapter1"]) +Object is a Node Set : +Set contains 1 nodes: +1 ELEMENT chapter + ATTRIBUTE id + TEXT + content=chapter1 diff --git a/result/XPath/xptr/chaptersrange b/result/XPath/xptr/chaptersrange new file mode 100644 index 00000000..0b85ee78 --- /dev/null +++ b/result/XPath/xptr/chaptersrange @@ -0,0 +1,48 @@ + +======================== +Expression: xpointer(//chapter[position() = 2]/range-to(following::chapter[1])) +Object is a Location Set: +1 : Object is a range : + From node + ELEMENT chapter + ATTRIBUTE id + TEXT + content=chapter2 + To node + ELEMENT chapter + ATTRIBUTE id + TEXT + content=chapter3 + + +======================== +Expression: xpointer(//chapter[position() <= 2]/range-to(following::chapter[1])) +Object is a Location Set: +1 : Object is a range : + From node + ELEMENT chapter + ATTRIBUTE id + TEXT + content=chapter1 + To node + ELEMENT chapter + ATTRIBUTE id + TEXT + content=chapter2 + +2 : Object is a range : + From node + ELEMENT chapter + ATTRIBUTE id + TEXT + content=chapter2 + To node + ELEMENT chapter + ATTRIBUTE id + TEXT + content=chapter3 + + +======================== +Expression: xpointer(//chapter[position() = last()]/range-to(following::chapter[1])) +Object is empty (NULL) diff --git a/result/XPath/xptr/vidbase b/result/XPath/xptr/vidbase new file mode 100644 index 00000000..8b9e92d6 --- /dev/null +++ b/result/XPath/xptr/vidbase @@ -0,0 +1,19 @@ + +======================== +Expression: xpointer(id('chapter1')/p) +Object is a Node Set : +Set contains 4 nodes: +1 ELEMENT p +2 ELEMENT p +3 ELEMENT p +4 ELEMENT p + +======================== +Expression: xpointer(id('chapter1')/p[1]/range-to(following-sibling::p[2])) +Object is a Location Set: +1 : Object is a range : + From node + ELEMENT p + To node + ELEMENT p + diff --git a/result/XPath/xptr/vidchildseq b/result/XPath/xptr/vidchildseq new file mode 100644 index 00000000..f06bb148 --- /dev/null +++ b/result/XPath/xptr/vidchildseq @@ -0,0 +1,18 @@ + +======================== +Expression: /1/2/3 +Object is a Node Set : +Set contains 1 nodes: +1 ELEMENT image + ATTRIBUTE href + TEXT + content=linus.gif + +======================== +Expression: chapter1/3 +Object is a Node Set : +Set contains 1 nodes: +1 ELEMENT image + ATTRIBUTE href + TEXT + content=linus.gif diff --git a/result/XPath/xptr/vidparts b/result/XPath/xptr/vidparts new file mode 100644 index 00000000..bd5bd3c1 --- /dev/null +++ b/result/XPath/xptr/vidparts @@ -0,0 +1,27 @@ + +======================== +Expression: xpointer(id("chapter1")) +Object is a Node Set : +Set contains 1 nodes: +1 ELEMENT chapter + ATTRIBUTE id + TEXT + content=chapter1 + +======================== +Expression: xpointer(//*[@id="chapter1"]) +Object is a Node Set : +Set contains 1 nodes: +1 ELEMENT chapter + ATTRIBUTE id + TEXT + content=chapter1 + +======================== +Expression: xpointer(id("chapter1"))xpointer(//*[@id="chapter1"]) +Object is a Node Set : +Set contains 1 nodes: +1 ELEMENT chapter + ATTRIBUTE id + TEXT + content=chapter1 diff --git a/test/XPath/docs/vid b/test/XPath/docs/vid new file mode 100644 index 00000000..cdb7437f --- /dev/null +++ b/test/XPath/docs/vid @@ -0,0 +1,43 @@ + + + + + + + + + + + +]> + + + + Welcome to Gnome + + + The Linux adventure +

bla bla bla ...

+ +

...

+

third p

+

fourth p

+
+ + Chapter 2 +

this is chapter 2 ...

+
+ + Chapter 3 +

this is chapter 3 ...

+
+ + Chapter 4 +

this is chapter 4 ...

+
+ + Chapter 5 +

this is chapter 5 ...

+
+
diff --git a/test/XPath/tests/vidbase b/test/XPath/tests/vidbase new file mode 100644 index 00000000..5cd79ac6 --- /dev/null +++ b/test/XPath/tests/vidbase @@ -0,0 +1,5 @@ +id('chapter1') +id('chapter3') +id('chapter1')/p +id('chapter1')//p +id('chapter1')/p[1] diff --git a/test/XPath/xptr/chapterschildseq b/test/XPath/xptr/chapterschildseq new file mode 100644 index 00000000..db6278f6 --- /dev/null +++ b/test/XPath/xptr/chapterschildseq @@ -0,0 +1,2 @@ +/1/2/3 +chapter1/3 diff --git a/test/XPath/xptr/chaptersparts b/test/XPath/xptr/chaptersparts new file mode 100644 index 00000000..aadc47c1 --- /dev/null +++ b/test/XPath/xptr/chaptersparts @@ -0,0 +1,6 @@ +xpointer(//chapitre[2]) +xpointer(//chapter[2]) +xpointer(//chapitre[2])xpointer(//chapter[2]) +xpointer(id("chapter1")) +xpointer(//*[@id="chapter1"]) +xpointer(id("chapter1"))xpointer(//*[@id="chapter1"]) diff --git a/test/XPath/xptr/chaptersrange b/test/XPath/xptr/chaptersrange new file mode 100644 index 00000000..0743111e --- /dev/null +++ b/test/XPath/xptr/chaptersrange @@ -0,0 +1,3 @@ +xpointer(//chapter[position() = 2]/range-to(following::chapter[1])) +xpointer(//chapter[position() <= 2]/range-to(following::chapter[1])) +xpointer(//chapter[position() = last()]/range-to(following::chapter[1])) diff --git a/test/XPath/xptr/vidbase b/test/XPath/xptr/vidbase new file mode 100644 index 00000000..b1463830 --- /dev/null +++ b/test/XPath/xptr/vidbase @@ -0,0 +1,2 @@ +xpointer(id('chapter1')/p) +xpointer(id('chapter1')/p[1]/range-to(following-sibling::p[2])) diff --git a/test/XPath/xptr/vidchildseq b/test/XPath/xptr/vidchildseq new file mode 100644 index 00000000..db6278f6 --- /dev/null +++ b/test/XPath/xptr/vidchildseq @@ -0,0 +1,2 @@ +/1/2/3 +chapter1/3 diff --git a/test/XPath/xptr/vidparts b/test/XPath/xptr/vidparts new file mode 100644 index 00000000..3afbbdde --- /dev/null +++ b/test/XPath/xptr/vidparts @@ -0,0 +1,3 @@ +xpointer(id("chapter1")) +xpointer(//*[@id="chapter1"]) +xpointer(id("chapter1"))xpointer(//*[@id="chapter1"]) diff --git a/xmlversion.h.in b/xmlversion.h.in index 6b41be44..ed1c43fd 100644 --- a/xmlversion.h.in +++ b/xmlversion.h.in @@ -77,6 +77,15 @@ extern void xmlCheckVersion(int version); #define LIBXML_XPATH_DISABLED #endif +/* + * Whether XPointer is configured in + */ +#if @WITH_XPTR@ +#define LIBXML_XPTR_ENABLED +#else +#define LIBXML_XPTR_DISABLED +#endif + /* * Whether iconv support is available */ diff --git a/xpath.c b/xpath.c index 840ae4df..1d307551 100644 --- a/xpath.c +++ b/xpath.c @@ -784,7 +784,7 @@ xmlXPathFreeObject(xmlXPathObjectPtr obj) { #ifdef LIBXML_XPTR_ENABLED } else if (obj->type == XPATH_LOCATIONSET) { if (obj->user != NULL) - xmlXPathFreeLocationSet(obj->user); + xmlXPtrFreeLocationSet(obj->user); #endif } else if (obj->type == XPATH_STRING) { if (obj->stringval != NULL) @@ -2118,6 +2118,16 @@ xmlXPathNodeCollectAndTest(xmlXPathParserContextPtr ctxt, xmlXPathAxisVal axis, } fprintf(xmlXPathDebug, "Testing : "); #endif + /* + * 2.3 Node Tests + * - For the attribute axis, the principal node type is attribute. + * - For the namespace axis, the principal node type is namespace. + * - For other axes, the principal node type is element. + * + * A node test * is true for any node of the + * principal node type. For example, child::* willi + * select all element children of the context node + */ for (i = 0;i < nodelist->nodeNr; i++) { ctxt->context->node = nodelist->nodeTab[i]; @@ -2157,8 +2167,8 @@ xmlXPathNodeCollectAndTest(xmlXPathParserContextPtr ctxt, xmlXPathAxisVal axis, break; case NODE_TEST_ALL: if ((cur->type == XML_ELEMENT_NODE) || - (cur->type == XML_ATTRIBUTE_NODE)) { - /* !!! || (cur->type == XML_TEXT_NODE)) { */ + (cur->type == XML_DOCUMENT_NODE) || + (cur->type == XML_HTML_DOCUMENT_NODE)) { #ifdef DEBUG_STEP n++; #endif @@ -4756,6 +4766,15 @@ eval_predicates: void xmlXPathEvalRelativeLocationPath(xmlXPathParserContextPtr ctxt) { SKIP_BLANKS; + if ((CUR == '/') && (NXT(1) == '/')) { + SKIP(2); + SKIP_BLANKS; + xmlXPathNodeCollectAndTest(ctxt, AXIS_DESCENDANT_OR_SELF, + NODE_TEST_TYPE, XML_ELEMENT_NODE, NULL, NULL); + } else if (CUR == '/') { + NEXT; + SKIP_BLANKS; + } xmlXPathEvalStep(ctxt); SKIP_BLANKS; while (CUR == '/') {