From 67f8b1cd960d809819342ada338444ed24739a55 Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Fri, 9 Apr 2004 21:51:49 +0000 Subject: [PATCH] adding xml:id draft support adding 4 first regression tests Daniel * SAX2.c include/libxml/tree.h: adding xml:id draft support * Makefile.am test/xmlid/id_tst* result/xmlid/id_tst*: adding 4 first regression tests Daniel --- ChangeLog | 6 ++++++ Makefile.am | 23 ++++++++++++++++++++++- SAX2.c | 21 ++++++++++++++++++++- include/libxml/tree.h | 7 +++++++ result/xmlid/id_tst1.xml | 6 ++++++ result/xmlid/id_tst1.xml.err | 0 result/xmlid/id_tst2.xml | 6 ++++++ result/xmlid/id_tst2.xml.err | 3 +++ result/xmlid/id_tst3.xml | 6 ++++++ result/xmlid/id_tst3.xml.err | 6 ++++++ result/xmlid/id_tst4.xml | 6 ++++++ result/xmlid/id_tst4.xml.err | 3 +++ test/xmlid/id_tst1.xml | 1 + test/xmlid/id_tst2.xml | 1 + test/xmlid/id_tst3.xml | 1 + test/xmlid/id_tst4.xml | 4 ++++ 16 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 result/xmlid/id_tst1.xml create mode 100644 result/xmlid/id_tst1.xml.err create mode 100644 result/xmlid/id_tst2.xml create mode 100644 result/xmlid/id_tst2.xml.err create mode 100644 result/xmlid/id_tst3.xml create mode 100644 result/xmlid/id_tst3.xml.err create mode 100644 result/xmlid/id_tst4.xml create mode 100644 result/xmlid/id_tst4.xml.err create mode 100644 test/xmlid/id_tst1.xml create mode 100644 test/xmlid/id_tst2.xml create mode 100644 test/xmlid/id_tst3.xml create mode 100644 test/xmlid/id_tst4.xml diff --git a/ChangeLog b/ChangeLog index bef0dadd..fb4cf825 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Fri Apr 9 23:49:37 CEST 2004 Daniel Veillard + + * SAX2.c include/libxml/tree.h: adding xml:id draft support + * Makefile.am test/xmlid/id_tst* result/xmlid/id_tst*: adding + 4 first regression tests + Fri Apr 9 11:56:08 CEST 2004 Daniel Veillard * libxml.spec.in: fixing Red Hat bug #120482 , libxml2-python diff --git a/Makefile.am b/Makefile.am index 1ac2fb5e..e567c861 100644 --- a/Makefile.am +++ b/Makefile.am @@ -122,7 +122,7 @@ check-local: tests testall : tests SVGtests SAXtests -tests: XMLtests XMLenttests NStests Errtests @READER_TEST@ @TEST_SAX@ @TEST_PUSH@ @TEST_HTML@ @TEST_PHTML@ @TEST_VALID@ URItests @TEST_XPATH@ @TEST_XPTR@ @TEST_XINCLUDE@ @TEST_C14N@ @TEST_DEBUG@ @TEST_CATALOG@ @TEST_REGEXPS@ @TEST_SCHEMAS@ @TEST_THREADS@ Timingtests @TEST_VTIME@ @PYTHON_TESTS@ +tests: XMLtests XMLenttests NStests IDtests Errtests @READER_TEST@ @TEST_SAX@ @TEST_PUSH@ @TEST_HTML@ @TEST_PHTML@ @TEST_VALID@ URItests @TEST_XPATH@ @TEST_XPTR@ @TEST_XINCLUDE@ @TEST_C14N@ @TEST_DEBUG@ @TEST_CATALOG@ @TEST_REGEXPS@ @TEST_SCHEMAS@ @TEST_THREADS@ Timingtests @TEST_VTIME@ @PYTHON_TESTS@ @(if [ "@PYTHON_SUBDIR@" != "" ] ; then cd python ; $(MAKE) tests ; fi) @(cd doc/examples ; $(MAKE) tests) @@ -281,6 +281,27 @@ NStests : xmllint$(EXEEXT) rm result.$$name error.$$name ; \ fi ; fi ; done) +IDtests : xmllint$(EXEEXT) testXPath$(EXEEXT) + @(echo > .memdump) + @echo "## xml:id regression tests" + -@(for i in $(srcdir)/test/xmlid/id_*.xml ; do \ + name=`basename $$i`; \ + if [ ! -d $$i ] ; then \ + if [ ! -f $(srcdir)/result/xmlid/$$name ] ; then \ + echo New test file $$name ; \ + $(CHECKER) $(top_builddir)/testXPath -i $$i "id('bar')" \ + 2> $(srcdir)/result/xmlid/$$name.err \ + > $(srcdir)/result/xmlid/$$name ; \ + grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0"; \ + else \ + log=`$(CHECKER) $(top_builddir)/testXPath -i $$i "id('bar')" 2> error.$$name > result.$$name ; \ + grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0"; \ + diff $(srcdir)/result/xmlid/$$name result.$$name ; \ + diff $(srcdir)/result/xmlid/$$name.err error.$$name` ; \ + if [ -n "$$log" ] ; then echo $$name result ; echo $$log ; fi ; \ + rm result.$$name error.$$name ; \ + fi ; fi ; done) + Errtests : xmllint$(EXEEXT) @(echo > .memdump) @echo "## Error cases regression tests" diff --git a/SAX2.c b/SAX2.c index e6e310e0..fdc537a5 100644 --- a/SAX2.c +++ b/SAX2.c @@ -1204,6 +1204,14 @@ xmlSAX2AttributeInternal(void *ctx, const xmlChar *fullname, xmlAddID(&ctxt->vctxt, ctxt->myDoc, value, ret); else if (xmlIsRef(ctxt->myDoc, ctxt->node, ret)) xmlAddRef(&ctxt->vctxt, ctxt->myDoc, value, ret); + else if (xmlStrEqual(fullname, BAD_CAST "xml:id")) { + /* + * Add the xml:id value + * + * Open issue: normalization of the value. + */ + xmlAddID(&ctxt->vctxt, ctxt->myDoc, value, ret); + } } error: @@ -1925,7 +1933,18 @@ xmlSAX2AttributeNs(xmlParserCtxtPtr ctxt, if (dup == NULL) dup = xmlStrndup(value, valueend - value); xmlAddRef(&ctxt->vctxt, ctxt->myDoc, dup, ret); - } + } else if ((prefix == ctxt->str_xml) && + (localname[0] == 'i') && (localname[1] == 'd') && + (localname[2] == 0)) { + /* + * Add the xml:id value + * + * Open issue: normalization of the value. + */ + if (dup == NULL) + dup = xmlStrndup(value, valueend - value); + xmlAddID(&ctxt->vctxt, ctxt->myDoc, dup, ret); + } } if (dup != NULL) xmlFree(dup); diff --git a/include/libxml/tree.h b/include/libxml/tree.h index bc4dbe36..470151d5 100644 --- a/include/libxml/tree.h +++ b/include/libxml/tree.h @@ -63,6 +63,13 @@ typedef xmlEntity *xmlEntityPtr; #define XML_XML_NAMESPACE \ (const xmlChar *) "http://www.w3.org/XML/1998/namespace" +/** + * XML_XML_ID: + * + * This is the name for the special xml:id attribute + */ +#define XML_XML_ID (const xmlChar *) "xml:id" + /* * The different element types carried by an XML tree. * diff --git a/result/xmlid/id_tst1.xml b/result/xmlid/id_tst1.xml new file mode 100644 index 00000000..33ee896d --- /dev/null +++ b/result/xmlid/id_tst1.xml @@ -0,0 +1,6 @@ +Object is a Node Set : +Set contains 1 nodes: +1 ELEMENT foo + ATTRIBUTE id + TEXT + content=bar diff --git a/result/xmlid/id_tst1.xml.err b/result/xmlid/id_tst1.xml.err new file mode 100644 index 00000000..e69de29b diff --git a/result/xmlid/id_tst2.xml b/result/xmlid/id_tst2.xml new file mode 100644 index 00000000..33ee896d --- /dev/null +++ b/result/xmlid/id_tst2.xml @@ -0,0 +1,6 @@ +Object is a Node Set : +Set contains 1 nodes: +1 ELEMENT foo + ATTRIBUTE id + TEXT + content=bar diff --git a/result/xmlid/id_tst2.xml.err b/result/xmlid/id_tst2.xml.err new file mode 100644 index 00000000..390d48d2 --- /dev/null +++ b/result/xmlid/id_tst2.xml.err @@ -0,0 +1,3 @@ +./test/xmlid/id_tst2.xml:1: namespace error : Namespace prefix n on foo is not defined + + ^ diff --git a/result/xmlid/id_tst3.xml b/result/xmlid/id_tst3.xml new file mode 100644 index 00000000..e2f82286 --- /dev/null +++ b/result/xmlid/id_tst3.xml @@ -0,0 +1,6 @@ +Object is a Node Set : +Set contains 1 nodes: +1 ELEMENT o:o + ATTRIBUTE id + TEXT + content=bar diff --git a/result/xmlid/id_tst3.xml.err b/result/xmlid/id_tst3.xml.err new file mode 100644 index 00000000..7aa3e1c9 --- /dev/null +++ b/result/xmlid/id_tst3.xml.err @@ -0,0 +1,6 @@ +./test/xmlid/id_tst3.xml:1: namespace error : Failed to parse QName 'f:o:' + + ^ +./test/xmlid/id_tst3.xml:1: namespace error : Namespace prefix f on o:o is not defined + + ^ diff --git a/result/xmlid/id_tst4.xml b/result/xmlid/id_tst4.xml new file mode 100644 index 00000000..33ee896d --- /dev/null +++ b/result/xmlid/id_tst4.xml @@ -0,0 +1,6 @@ +Object is a Node Set : +Set contains 1 nodes: +1 ELEMENT foo + ATTRIBUTE id + TEXT + content=bar diff --git a/result/xmlid/id_tst4.xml.err b/result/xmlid/id_tst4.xml.err new file mode 100644 index 00000000..36c78c8c --- /dev/null +++ b/result/xmlid/id_tst4.xml.err @@ -0,0 +1,3 @@ +./test/xmlid/id_tst4.xml:3: element err: validity error : ID bar already defined + + ^ diff --git a/test/xmlid/id_tst1.xml b/test/xmlid/id_tst1.xml new file mode 100644 index 00000000..7c3249cc --- /dev/null +++ b/test/xmlid/id_tst1.xml @@ -0,0 +1 @@ + diff --git a/test/xmlid/id_tst2.xml b/test/xmlid/id_tst2.xml new file mode 100644 index 00000000..2bf5861e --- /dev/null +++ b/test/xmlid/id_tst2.xml @@ -0,0 +1 @@ + diff --git a/test/xmlid/id_tst3.xml b/test/xmlid/id_tst3.xml new file mode 100644 index 00000000..7316a132 --- /dev/null +++ b/test/xmlid/id_tst3.xml @@ -0,0 +1 @@ + diff --git a/test/xmlid/id_tst4.xml b/test/xmlid/id_tst4.xml new file mode 100644 index 00000000..ea057a30 --- /dev/null +++ b/test/xmlid/id_tst4.xml @@ -0,0 +1,4 @@ + + + +