added io1.c an example ox xmlIO usage and io1.res test result, fixed a

* doc/examples/*: added io1.c an example ox xmlIO usage and io1.res
  test result, fixed a awful lot of memory leaks showing up in
  testWriter.c, changed the examples and the Makefiles to test
  memory leaks.
* xmlwriter.c: fixed a memory leak
* Makefile.am: run the doc/examples regression tests as part of
  make tests
* xpath.c include/libxml/xpath.h: added xmlXPathCtxtCompile() to
  compile an XPath expression within a context, currently the goal
  is to be able to reuse the XSLT stylesheet dictionnary, but this
  opens the door to others possible optimizations.
* dict.c include/libxml/dict.h: added xmlDictCreateSub() which allows
  to build a new dictionnary based on another read-only dictionnary.
  This is needed for XSLT to keep the stylesheet dictionnary read-only
  while being able to reuse the strings for the transformation
  dictionnary.
* xinclude.c: fixed a dictionnar reference counting problem occuring
  when document parsing failed.
* testSAX.c: adding option --repeat for timing 100times the parsing
* doc/* : rebuilt all the docs
Daniel
diff --git a/ChangeLog b/ChangeLog
index e19dabd..4dfae89 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,26 @@
+Fri Jan 23 14:03:21 CET 2004 Daniel Veillard <daniel@veillard.com>
+
+	* doc/examples/*: added io1.c an example ox xmlIO usage and io1.res
+	  test result, fixed a awful lot of memory leaks showing up in
+	  testWriter.c, changed the examples and the Makefiles to test
+	  memory leaks.
+	* xmlwriter.c: fixed a memory leak
+	* Makefile.am: run the doc/examples regression tests as part of
+	  make tests
+	* xpath.c include/libxml/xpath.h: added xmlXPathCtxtCompile() to
+	  compile an XPath expression within a context, currently the goal
+	  is to be able to reuse the XSLT stylesheet dictionnary, but this
+	  opens the door to others possible optimizations.
+	* dict.c include/libxml/dict.h: added xmlDictCreateSub() which allows
+	  to build a new dictionnary based on another read-only dictionnary.
+	  This is needed for XSLT to keep the stylesheet dictionnary read-only
+	  while being able to reuse the strings for the transformation
+	  dictionnary.
+	* xinclude.c: fixed a dictionnar reference counting problem occuring
+	  when document parsing failed.
+	* testSAX.c: adding option --repeat for timing 100times the parsing
+	* doc/* : rebuilt all the docs
+
 Thu Jan 22 14:17:05 2004  Aleksey Sanin  <aleksey@aleksey.com>
 
 	* xmlmemory.c: make xmlReallocLoc() accept NULL pointer
diff --git a/Makefile.am b/Makefile.am
index 9075bfc..451f4ad 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -124,6 +124,7 @@
 
 tests: XMLtests XMLenttests NStests @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@
 	@(if [ "@PYTHON_SUBDIR@" != "" ] ; then cd python ; $(MAKE) tests ; fi)
+	@(cd doc/examples ; $(MAKE) tests)
 
 valgrind:
 	@echo '## Running the regression tests under Valgrind'
diff --git a/dict.c b/dict.c
index 0a9aebe..2ffd6a5 100644
--- a/dict.c
+++ b/dict.c
@@ -65,6 +65,8 @@
     int size;
     int nbElems;
     xmlDictStringsPtr strings;
+
+    struct _xmlDict *subdict;
 };
 
 /*
@@ -181,11 +183,12 @@
  * Calculate the hash key
  */
 static unsigned long
-xmlDictComputeKey(xmlDictPtr dict, const xmlChar *name, int namelen) {
+xmlDictComputeKey(const xmlChar *name, int namelen) {
     unsigned long value = 0L;
     
     if (name == NULL) return(0);
-    value += 30 * (*name);
+    value = *name;
+    value <<= 5;
     if (namelen > 10) {
         value += name[namelen - 1];
         namelen = 10;
@@ -200,10 +203,9 @@
         case 4: value += name[3];
         case 3: value += name[2];
         case 2: value += name[1];
-        case 1: value += name[0];
         default: break;
     }
-    return (value % dict->size);
+    return(value);
 }
 
 /*
@@ -211,14 +213,13 @@
  * Calculate the hash key
  */
 static unsigned long
-xmlDictComputeQKey(xmlDictPtr dict, const xmlChar *prefix,
-                   const xmlChar *name, int len)
+xmlDictComputeQKey(const xmlChar *prefix, const xmlChar *name, int len)
 {
     unsigned long value = 0L;
     int plen;
     
     if (prefix == NULL)
-        return(xmlDictComputeKey(dict, name, len));
+        return(xmlDictComputeKey(name, len));
 
     plen = xmlStrlen(prefix);
     if (plen == 0)
@@ -263,7 +264,7 @@
         case 1: value += name[0];
         default: break;
     }
-    return (value % dict->size);
+    return(value);
 }
 
 /**
@@ -271,7 +272,7 @@
  *
  * Create a new dictionary
  *
- * Returns the newly created object, or NULL if an error occured.
+ * Returns the newly created dictionnary, or NULL if an error occured.
  */
 xmlDictPtr
 xmlDictCreate(void) {
@@ -285,6 +286,7 @@
 	dict->nbElems = 0;
         dict->dict = xmlMalloc(MIN_DICT_SIZE * sizeof(xmlDictEntry));
 	dict->strings = NULL;
+	dict->subdict = NULL;
         if (dict->dict) {
   	    memset(dict->dict, 0, MIN_DICT_SIZE * sizeof(xmlDictEntry));
   	    return(dict);
@@ -295,6 +297,28 @@
 }
 
 /**
+ * xmlDictCreateSub:
+ * @sub: an existing dictionnary
+ *
+ * Create a new dictionary, inheriting strings from the read-only
+ * dictionnary @sub. On lookup, strings are first searched in the
+ * new dictionnary, then in @sub, and if not found are created in the
+ * new dictionnary.
+ *
+ * Returns the newly created dictionnary, or NULL if an error occured.
+ */
+xmlDictPtr
+xmlDictCreateSub(xmlDictPtr sub) {
+    xmlDictPtr dict = xmlDictCreate();
+  
+    if ((dict != NULL) && (sub != NULL)) {
+        dict->subdict = sub;
+	xmlDictReference(dict->subdict);
+    }
+    return(dict);
+}
+
+/**
  * xmlDictReference:
  * @dict: the dictionnary
  *
@@ -357,7 +381,7 @@
     for (i = 0; i < oldsize; i++) {
 	if (olddict[i].valid == 0) 
 	    continue;
-	key = xmlDictComputeKey(dict, olddict[i].name, olddict[i].len);
+	key = xmlDictComputeKey(olddict[i].name, olddict[i].len) % dict->size;
 	memcpy(&(dict->dict[key]), &(olddict[i]), sizeof(xmlDictEntry));
 	dict->dict[key].next = NULL;
 #ifdef DEBUG_GROW
@@ -374,7 +398,7 @@
 	     * put back the entry in the new dict
 	     */
 
-	    key = xmlDictComputeKey(dict, iter->name, iter->len);
+	    key = xmlDictComputeKey(iter->name, iter->len) % dict->size;
 	    if (dict->dict[key].valid == 0) {
 		memcpy(&(dict->dict[key]), iter, sizeof(xmlDictEntry));
 		dict->dict[key].next = NULL;
@@ -425,6 +449,10 @@
     dict->ref_counter--;
     if (dict->ref_counter > 0) return;
 
+    if (dict->subdict != NULL) {
+        xmlDictFree(dict->subdict);
+    }
+
     if (dict->dict) {
 	for(i = 0; ((i < dict->size) && (dict->nbElems > 0)); i++) {
 	    iter = &(dict->dict[i]);
@@ -464,7 +492,7 @@
  */
 const xmlChar *
 xmlDictLookup(xmlDictPtr dict, const xmlChar *name, int len) {
-    unsigned long key, nbi = 0;
+    unsigned long key, okey, nbi = 0;
     xmlDictEntryPtr entry;
     xmlDictEntryPtr insert;
     const xmlChar *ret;
@@ -478,7 +506,8 @@
     /*
      * Check for duplicate and insertion location.
      */
-    key = xmlDictComputeKey(dict, name, len);
+    okey = xmlDictComputeKey(name, len);
+    key = okey % dict->size;
     if (dict->dict[key].valid == 0) {
 	insert = NULL;
     } else {
@@ -486,8 +515,7 @@
 	     insert = insert->next) {
 #ifdef __GNUC__
 	    if (insert->len == len) {
-	        register int tmp = memcmp(insert->name, name, len);
-		if (!tmp)
+		if (!memcmp(insert->name, name, len))
 		    return(insert->name);
 	    }
 #else
@@ -499,8 +527,7 @@
 	}
 #ifdef __GNUC__
 	if (insert->len == len) {
-	    register int tmp = memcmp(insert->name, name, len);
-	    if (!tmp)
+	    if (!memcmp(insert->name, name, len))
 		return(insert->name);
 	}
 #else
@@ -510,6 +537,39 @@
 #endif
     }
 
+    if (dict->subdict) {
+	key = okey % dict->subdict->size;
+	if (dict->subdict->dict[key].valid != 0) {
+	    xmlDictEntryPtr tmp;
+
+	    for (tmp = &(dict->subdict->dict[key]); tmp->next != NULL;
+		 tmp = tmp->next) {
+#ifdef __GNUC__
+		if (tmp->len == len) {
+		    if (!memcmp(tmp->name, name, len))
+			return(tmp->name);
+		}
+#else
+		if ((tmp->len == len) &&
+		    (!xmlStrncmp(tmp->name, name, len)))
+		    return(tmp->name);
+#endif
+		nbi++;
+	    }
+#ifdef __GNUC__
+	    if (tmp->len == len) {
+		if (!memcmp(tmp->name, name, len))
+		    return(tmp->name);
+	    }
+#else
+	    if ((tmp->len == len) &&
+		(!xmlStrncmp(tmp->name, name, len)))
+		return(tmp->name);
+#endif
+	}
+	key = okey % dict->size;
+    }
+
     ret = xmlDictAddString(dict, name, len);
     if (ret == NULL)
         return(NULL);
@@ -551,7 +611,7 @@
  */
 const xmlChar *
 xmlDictQLookup(xmlDictPtr dict, const xmlChar *prefix, const xmlChar *name) {
-    unsigned long key, nbi = 0;
+    unsigned long okey, key, nbi = 0;
     xmlDictEntryPtr entry;
     xmlDictEntryPtr insert;
     const xmlChar *ret;
@@ -567,7 +627,8 @@
     /*
      * Check for duplicate and insertion location.
      */
-    key = xmlDictComputeQKey(dict, prefix, name, len);
+    okey = xmlDictComputeQKey(prefix, name, len);
+    key = okey % dict->size;
     if (dict->dict[key].valid == 0) {
 	insert = NULL;
     } else {
@@ -583,6 +644,24 @@
 	    return(insert->name);
     }
 
+    if (dict->subdict) {
+	key = okey % dict->subdict->size;
+	if (dict->subdict->dict[key].valid != 0) {
+	    xmlDictEntryPtr tmp;
+	    for (tmp = &(dict->subdict->dict[key]); tmp->next != NULL;
+		 tmp = tmp->next) {
+		if ((tmp->len == len) &&
+		    (xmlStrQEqual(prefix, name, tmp->name)))
+		    return(tmp->name);
+		nbi++;
+	    }
+	    if ((tmp->len == len) &&
+		(xmlStrQEqual(prefix, name, tmp->name)))
+		return(tmp->name);
+	}
+	key = okey % dict->size;
+    }
+
     ret = xmlDictAddQString(dict, prefix, name, len);
     if (ret == NULL)
         return(NULL);
@@ -633,6 +712,8 @@
 	    return(1);
 	pool = pool->next;
     }
+    if (dict->subdict)
+        return(xmlDictOwns(dict->subdict, str));
     return(0);
 }
 
@@ -649,6 +730,8 @@
 xmlDictSize(xmlDictPtr dict) {
     if (dict == NULL)
 	return(-1);
+    if (dict->subdict)
+        return(dict->nbElems + dict->subdict->nbElems);
     return(dict->nbElems);
 }
 
diff --git a/doc/APIchunk11.html b/doc/APIchunk11.html
index 7756005..37a4f3b 100644
--- a/doc/APIchunk11.html
+++ b/doc/APIchunk11.html
@@ -335,8 +335,12 @@
 </dd><dt>dict</dt><dd><a href="html/libxml-tree.html#_xmlDoc">_xmlDoc</a><br />
 </dd><dt>dictionary</dt><dd><a href="html/libxml-parser.html#_xmlParserCtxt">_xmlParserCtxt</a><br />
 <a href="html/libxml-dict.html#xmlDictCreate">xmlDictCreate</a><br />
+<a href="html/libxml-dict.html#xmlDictCreateSub">xmlDictCreateSub</a><br />
 <a href="html/libxml-dict.html#xmlDictReference">xmlDictReference</a><br />
 </dd><dt>dictionnary</dt><dd><a href="html/libxml-parser.html#_xmlParserCtxt">_xmlParserCtxt</a><br />
+<a href="html/libxml-xpath.html#_xmlXPathContext">_xmlXPathContext</a><br />
+<a href="html/libxml-dict.html#xmlDictCreate">xmlDictCreate</a><br />
+<a href="html/libxml-dict.html#xmlDictCreateSub">xmlDictCreateSub</a><br />
 <a href="html/libxml-dict.html#xmlDictFree">xmlDictFree</a><br />
 <a href="html/libxml-dict.html#xmlDictLookup">xmlDictLookup</a><br />
 <a href="html/libxml-dict.html#xmlDictOwns">xmlDictOwns</a><br />
diff --git a/doc/APIchunk15.html b/doc/APIchunk15.html
index 82af4ce..6ca853b 100644
--- a/doc/APIchunk15.html
+++ b/doc/APIchunk15.html
@@ -289,6 +289,7 @@
 <a href="html/libxml-parserInternals.html#xmlEntityReferenceFunc">xmlEntityReferenceFunc</a><br />
 <a href="html/libxml-tree.html#xmlNodeGetSpacePreserve">xmlNodeGetSpacePreserve</a><br />
 <a href="html/libxml-xpathInternals.html#xmlXPathNextAttribute">xmlXPathNextAttribute</a><br />
+</dd><dt>inheriting</dt><dd><a href="html/libxml-dict.html#xmlDictCreateSub">xmlDictCreateSub</a><br />
 </dd><dt>inherits</dt><dd><a href="html/libxml-tree.html#xmlNewChild">xmlNewChild</a><br />
 <a href="html/libxml-tree.html#xmlNewTextChild">xmlNewTextChild</a><br />
 </dd><dt>initial</dt><dd><a href="html/libxml-tree.html#_xmlDoc">_xmlDoc</a><br />
diff --git a/doc/APIchunk19.html b/doc/APIchunk19.html
index f533644..bc86e59 100644
--- a/doc/APIchunk19.html
+++ b/doc/APIchunk19.html
@@ -53,6 +53,7 @@
 <a href="html/libxml-parserInternals.html#xmlParseMarkupDecl">xmlParseMarkupDecl</a><br />
 </dd><dt>occured</dt><dd><a href="html/libxml-xmlerror.html#xmlCtxtGetLastError">xmlCtxtGetLastError</a><br />
 <a href="html/libxml-dict.html#xmlDictCreate">xmlDictCreate</a><br />
+<a href="html/libxml-dict.html#xmlDictCreateSub">xmlDictCreateSub</a><br />
 <a href="html/libxml-xmlerror.html#xmlGetLastError">xmlGetLastError</a><br />
 <a href="html/libxml-hash.html#xmlHashCreate">xmlHashCreate</a><br />
 <a href="html/libxml-list.html#xmlListRemoveFirst">xmlListRemoveFirst</a><br />
diff --git a/doc/APIchunk21.html b/doc/APIchunk21.html
index e974f05..ee86483 100644
--- a/doc/APIchunk21.html
+++ b/doc/APIchunk21.html
@@ -106,6 +106,7 @@
 <a href="html/libxml-threads.html#xmlUnlockLibrary">xmlUnlockLibrary</a><br />
 </dd><dt>reached</dt><dd><a href="html/libxml-xmlregexp.html#xmlRegExecPushString">xmlRegExecPushString</a><br />
 <a href="html/libxml-xmlregexp.html#xmlRegExecPushString2">xmlRegExecPushString2</a><br />
+</dd><dt>read-only</dt><dd><a href="html/libxml-dict.html#xmlDictCreateSub">xmlDictCreateSub</a><br />
 </dd><dt>readable</dt><dd><a href="html/libxml-xmlstring.html#xmlStrEqual">xmlStrEqual</a><br />
 </dd><dt>reader</dt><dd><a href="html/libxml-parser.html#xmlCtxtReadFd">xmlCtxtReadFd</a><br />
 <a href="html/libxml-xmlreader.html#xmlFreeTextReader">xmlFreeTextReader</a><br />
diff --git a/doc/APIchunk22.html b/doc/APIchunk22.html
index b689d43..3e8d7e7 100644
--- a/doc/APIchunk22.html
+++ b/doc/APIchunk22.html
@@ -136,6 +136,7 @@
 <a href="html/libxml-xmlstring.html#xmlStrcasestr">xmlStrcasestr</a><br />
 <a href="html/libxml-xmlstring.html#xmlStrchr">xmlStrchr</a><br />
 <a href="html/libxml-xmlstring.html#xmlStrstr">xmlStrstr</a><br />
+</dd><dt>searched</dt><dd><a href="html/libxml-dict.html#xmlDictCreateSub">xmlDictCreateSub</a><br />
 </dd><dt>section</dt><dd><a href="html/libxml-HTMLtree.html#HTML_PRESERVE_NODE">HTML_PRESERVE_NODE</a><br />
 <a href="html/libxml-uri.html#xmlBuildURI">xmlBuildURI</a><br />
 <a href="html/libxml-catalog.html#xmlCatalogSetDefaultPrefer">xmlCatalogSetDefaultPrefer</a><br />
@@ -603,6 +604,7 @@
 <a href="html/libxml-xpathInternals.html#xmlXPathStringLengthFunction">xmlXPathStringLengthFunction</a><br />
 </dd><dt>stringi</dt><dd><a href="html/libxml-xpathInternals.html#xmlXPathSubstringAfterFunction">xmlXPathSubstringAfterFunction</a><br />
 </dd><dt>strings</dt><dd><a href="html/libxml-parser.html#_xmlParserCtxt">_xmlParserCtxt</a><br />
+<a href="html/libxml-dict.html#xmlDictCreateSub">xmlDictCreateSub</a><br />
 <a href="html/libxml-parser.html#xmlGetFeaturesList">xmlGetFeaturesList</a><br />
 <a href="html/libxml-pattern.html#xmlPatterncompile">xmlPatterncompile</a><br />
 <a href="html/libxml-xmlregexp.html#xmlRegexpCompile">xmlRegexpCompile</a><br />
diff --git a/doc/APIconstructors.html b/doc/APIconstructors.html
index 9949bce..e5a8fd2 100644
--- a/doc/APIconstructors.html
+++ b/doc/APIconstructors.html
@@ -243,6 +243,7 @@
 </p><h2>Type xmlDeregisterNodeFunc:</h2><p><a href="html/libxml-globals.html#xmlDeregisterNodeDefault">xmlDeregisterNodeDefault</a><br />
 <a href="html/libxml-globals.html#xmlThrDefDeregisterNodeDefault">xmlThrDefDeregisterNodeDefault</a><br />
 </p><h2>Type xmlDictPtr:</h2><p><a href="html/libxml-dict.html#xmlDictCreate">xmlDictCreate</a><br />
+<a href="html/libxml-dict.html#xmlDictCreateSub">xmlDictCreateSub</a><br />
 </p><h2>Type xmlDocPtr:</h2><p><a href="html/libxml-tree.html#xmlCopyDoc">xmlCopyDoc</a><br />
 <a href="html/libxml-parser.html#xmlCtxtReadDoc">xmlCtxtReadDoc</a><br />
 <a href="html/libxml-parser.html#xmlCtxtReadFd">xmlCtxtReadFd</a><br />
@@ -470,6 +471,7 @@
 </p><h2>Type xmlValidCtxtPtr:</h2><p><a href="html/libxml-valid.html#xmlNewValidCtxt">xmlNewValidCtxt</a><br />
 </p><h2>Type xmlXIncludeCtxtPtr:</h2><p><a href="html/libxml-xinclude.html#xmlXIncludeNewContext">xmlXIncludeNewContext</a><br />
 </p><h2>Type xmlXPathCompExprPtr:</h2><p><a href="html/libxml-xpath.html#xmlXPathCompile">xmlXPathCompile</a><br />
+<a href="html/libxml-xpath.html#xmlXPathCtxtCompile">xmlXPathCtxtCompile</a><br />
 </p><h2>Type xmlXPathContextPtr:</h2><p><a href="html/libxml-xpath.html#xmlXPathNewContext">xmlXPathNewContext</a><br />
 <a href="html/libxml-xpointer.html#xmlXPtrNewContext">xmlXPtrNewContext</a><br />
 </p><h2>Type xmlXPathFunction:</h2><p><a href="html/libxml-xpathInternals.html#xmlXPathFuncLookupFunc">xmlXPathFuncLookupFunc</a><br />
diff --git a/doc/APIfiles.html b/doc/APIfiles.html
index 40e47a0..b4513b0 100644
--- a/doc/APIfiles.html
+++ b/doc/APIfiles.html
@@ -320,6 +320,7 @@
 <a href="html/libxml-debugXML.html#xmlShellWrite">xmlShellWrite</a><br />
 </p><h2><a name="dict" id="dict">Module dict</a>:</h2><p><a href="html/libxml-dict.html#xmlDict">xmlDict</a><br />
 <a href="html/libxml-dict.html#xmlDictCreate">xmlDictCreate</a><br />
+<a href="html/libxml-dict.html#xmlDictCreateSub">xmlDictCreateSub</a><br />
 <a href="html/libxml-dict.html#xmlDictFree">xmlDictFree</a><br />
 <a href="html/libxml-dict.html#xmlDictLookup">xmlDictLookup</a><br />
 <a href="html/libxml-dict.html#xmlDictOwns">xmlDictOwns</a><br />
@@ -2635,6 +2636,7 @@
 <a href="html/libxml-xpath.html#xmlXPathConvertFunc">xmlXPathConvertFunc</a><br />
 <a href="html/libxml-xpath.html#xmlXPathConvertNumber">xmlXPathConvertNumber</a><br />
 <a href="html/libxml-xpath.html#xmlXPathConvertString">xmlXPathConvertString</a><br />
+<a href="html/libxml-xpath.html#xmlXPathCtxtCompile">xmlXPathCtxtCompile</a><br />
 <a href="html/libxml-xpath.html#xmlXPathError">xmlXPathError</a><br />
 <a href="html/libxml-xpath.html#xmlXPathEval">xmlXPathEval</a><br />
 <a href="html/libxml-xpath.html#xmlXPathEvalExpression">xmlXPathEvalExpression</a><br />
diff --git a/doc/APIfunctions.html b/doc/APIfunctions.html
index da41766..858aefc 100644
--- a/doc/APIfunctions.html
+++ b/doc/APIfunctions.html
@@ -443,6 +443,7 @@
 <a href="html/libxml-xpath.html#xmlXPathCastStringToBoolean">xmlXPathCastStringToBoolean</a><br />
 <a href="html/libxml-xpath.html#xmlXPathCastStringToNumber">xmlXPathCastStringToNumber</a><br />
 <a href="html/libxml-xpath.html#xmlXPathCompile">xmlXPathCompile</a><br />
+<a href="html/libxml-xpath.html#xmlXPathCtxtCompile">xmlXPathCtxtCompile</a><br />
 <a href="html/libxml-xpath.html#xmlXPathEval">xmlXPathEval</a><br />
 <a href="html/libxml-xpath.html#xmlXPathEvalExpression">xmlXPathEvalExpression</a><br />
 <a href="html/libxml-xpathInternals.html#xmlXPathFuncLookupFunc">xmlXPathFuncLookupFunc</a><br />
@@ -997,7 +998,8 @@
 </p><h2>Type xmlDeregisterNodeFunc:</h2><p><a href="html/libxml-globals.html#xmlDeregisterNodeDefault">xmlDeregisterNodeDefault</a><br />
 <a href="html/libxml-globals.html#xmlThrDefDeregisterNodeDefault">xmlThrDefDeregisterNodeDefault</a><br />
 </p><h2>Type xmlDict *:</h2><p><a href="html/libxml-pattern.html#xmlPatterncompile">xmlPatterncompile</a><br />
-</p><h2>Type xmlDictPtr:</h2><p><a href="html/libxml-dict.html#xmlDictFree">xmlDictFree</a><br />
+</p><h2>Type xmlDictPtr:</h2><p><a href="html/libxml-dict.html#xmlDictCreateSub">xmlDictCreateSub</a><br />
+<a href="html/libxml-dict.html#xmlDictFree">xmlDictFree</a><br />
 <a href="html/libxml-dict.html#xmlDictLookup">xmlDictLookup</a><br />
 <a href="html/libxml-dict.html#xmlDictOwns">xmlDictOwns</a><br />
 <a href="html/libxml-dict.html#xmlDictQLookup">xmlDictQLookup</a><br />
@@ -1921,6 +1923,7 @@
 <a href="html/libxml-xpathInternals.html#xmlXPathDebugDumpCompExpr">xmlXPathDebugDumpCompExpr</a><br />
 <a href="html/libxml-xpath.html#xmlXPathFreeCompExpr">xmlXPathFreeCompExpr</a><br />
 </p><h2>Type xmlXPathContextPtr:</h2><p><a href="html/libxml-xpath.html#xmlXPathCompiledEval">xmlXPathCompiledEval</a><br />
+<a href="html/libxml-xpath.html#xmlXPathCtxtCompile">xmlXPathCtxtCompile</a><br />
 <a href="html/libxml-xpath.html#xmlXPathEval">xmlXPathEval</a><br />
 <a href="html/libxml-xpath.html#xmlXPathEvalExpression">xmlXPathEvalExpression</a><br />
 <a href="html/libxml-xpath.html#xmlXPathEvalPredicate">xmlXPathEvalPredicate</a><br />
diff --git a/doc/APIsymbols.html b/doc/APIsymbols.html
index 92110d8..16401c5 100644
--- a/doc/APIsymbols.html
+++ b/doc/APIsymbols.html
@@ -1402,6 +1402,7 @@
 <a href="html/libxml-encoding.html#xmlDetectCharEncoding">xmlDetectCharEncoding</a><br />
 <a href="html/libxml-dict.html#xmlDict">xmlDict</a><br />
 <a href="html/libxml-dict.html#xmlDictCreate">xmlDictCreate</a><br />
+<a href="html/libxml-dict.html#xmlDictCreateSub">xmlDictCreateSub</a><br />
 <a href="html/libxml-dict.html#xmlDictFree">xmlDictFree</a><br />
 <a href="html/libxml-dict.html#xmlDictLookup">xmlDictLookup</a><br />
 <a href="html/libxml-dict.html#xmlDictOwns">xmlDictOwns</a><br />
@@ -2654,6 +2655,7 @@
 <a href="html/libxml-xpath.html#xmlXPathConvertNumber">xmlXPathConvertNumber</a><br />
 <a href="html/libxml-xpath.html#xmlXPathConvertString">xmlXPathConvertString</a><br />
 <a href="html/libxml-xpathInternals.html#xmlXPathCountFunction">xmlXPathCountFunction</a><br />
+<a href="html/libxml-xpath.html#xmlXPathCtxtCompile">xmlXPathCtxtCompile</a><br />
 <a href="html/libxml-xpathInternals.html#xmlXPathDebugDumpCompExpr">xmlXPathDebugDumpCompExpr</a><br />
 <a href="html/libxml-xpathInternals.html#xmlXPathDebugDumpObject">xmlXPathDebugDumpObject</a><br />
 <a href="html/libxml-xpathInternals.html#xmlXPathDifference">xmlXPathDifference</a><br />
diff --git a/doc/examples/.cvsignore b/doc/examples/.cvsignore
index 1722271..00877b2 100644
--- a/doc/examples/.cvsignore
+++ b/doc/examples/.cvsignore
@@ -10,3 +10,4 @@
 reader1
 reader2
 reader3
+io1
diff --git a/doc/examples/Makefile.am b/doc/examples/Makefile.am
index 61136ab..3dfc8cf 100644
--- a/doc/examples/Makefile.am
+++ b/doc/examples/Makefile.am
@@ -19,9 +19,9 @@
 	$(mkinstalldirs) $(DESTDIR)$(TARGET_DIR)
 	-@INSTALL@ -m 0644 $(srcdir)/*.html $(srcdir)/*.c $(srcdir)/*.xml $(srcdir)/*.xsl $(srcdir)/*.res $(DESTDIR)$(TARGET_DIR)
 
-EXTRA_DIST=examples.xsl index.py test1.xml examples.xml test2.xml writer.xml test3.xml reader1.res reader3.res tree1.res tree2.res 
+EXTRA_DIST=examples.xsl index.py test1.xml examples.xml test2.xml writer.xml test3.xml reader1.res reader3.res tree1.res tree2.res io1.res 
 
-noinst_PROGRAMS=xpath1 parse1 parse2 tree1 tree2 testWriter reader1 reader2 reader3 
+noinst_PROGRAMS=xpath1 parse1 parse2 tree1 tree2 testWriter reader1 reader2 reader3 io1 
 
 xpath1_SOURCES=xpath1.c
 xpath1_LDFLAGS=
@@ -68,14 +68,30 @@
 reader3_DEPENDENCIES= $(DEPS)
 reader3_LDADD= @RDL_LIBS@ $(LDADDS)
 
+io1_SOURCES=io1.c
+io1_LDFLAGS=
+io1_DEPENDENCIES= $(DEPS)
+io1_LDADD= @RDL_LIBS@ $(LDADDS)
+
 tests: $(noinst_PROGRAMS)
+	@(echo > .memdump)
 	@(parse1 test1.xml)
+	@(grep "MORY ALLO" .memdump  | grep -v "MEMORY ALLOCATED : 0" ; exit 0)
 	@(parse2 test2.xml)
+	@(grep "MORY ALLO" .memdump  | grep -v "MEMORY ALLOCATED : 0" ; exit 0)
 	@(tree1 test2.xml > tree1.tmp ; diff tree1.tmp tree1.res ; rm tree1.tmp)
+	@(grep "MORY ALLO" .memdump  | grep -v "MEMORY ALLOCATED : 0" ; exit 0)
 	@(tree2 > tree2.tmp ; diff tree2.tmp tree2.res ; rm tree2.tmp)
+	@(grep "MORY ALLO" .memdump  | grep -v "MEMORY ALLOCATED : 0" ; exit 0)
 	@(testWriter ; for i in 1 2 3 4 ; do diff writer.xml writer$$i.res ; done ; rm writer*.res)
+	@(grep "MORY ALLO" .memdump  | grep -v "MEMORY ALLOCATED : 0" ; exit 0)
 	@(reader1 test2.xml > reader1.tmp ; diff reader1.tmp reader1.res ; rm reader1.tmp)
+	@(grep "MORY ALLO" .memdump  | grep -v "MEMORY ALLOCATED : 0" ; exit 0)
 	@(reader2 test2.xml > reader1.tmp ; diff reader1.tmp reader1.res ; rm reader1.tmp)
+	@(grep "MORY ALLO" .memdump  | grep -v "MEMORY ALLOCATED : 0" ; exit 0)
 	@(reader3 > reader3.tmp ; diff reader3.tmp reader3.res ; rm reader3.tmp)
+	@(grep "MORY ALLO" .memdump  | grep -v "MEMORY ALLOCATED : 0" ; exit 0)
+	@(io1 > io1.tmp ; diff io1.tmp io1.res ; rm -f io1.tmp)
+	@(grep "MORY ALLO" .memdump  | grep -v "MEMORY ALLOCATED : 0" ; exit 0)
 
 
diff --git a/doc/examples/examples.xml b/doc/examples/examples.xml
index 20e562f..c797383 100644
--- a/doc/examples/examples.xml
+++ b/doc/examples/examples.xml
@@ -13,25 +13,27 @@
       <include>&lt;libxml/tree.h&gt;</include>
     </includes>
     <uses>
-      <typedef line='80' file='xpath' name='xmlXPathObjectPtr'/>
-      <enum line='221' file='tree' name='XML_ELEMENT_NODE'/>
-      <function line='109' file='xpath' name='xmlXPathEvalExpression'/>
-      <function line='178' file='xpathInternals' name='xmlXPathRegisterNs'/>
-      <function line='121' file='xpath' name='xmlXPathFreeObject'/>
-      <typedef line='78' file='tree' name='xmlDocPtr'/>
-      <typedef line='210' file='tree' name='xmlNsPtr'/>
-      <function line='93' file='xpath' name='xmlXPathNewContext'/>
+      <enum line='225' file='tree' name='XML_ELEMENT_NODE'/>
+      <typedef line='84' file='xpath' name='xmlXPathObjectPtr'/>
+      <function line='50' file='xmlmemory' name='xmlMemoryDump'/>
+      <function line='113' file='xpath' name='xmlXPathEvalExpression'/>
+      <function line='182' file='xpathInternals' name='xmlXPathRegisterNs'/>
+      <function line='125' file='xpath' name='xmlXPathFreeObject'/>
+      <typedef line='82' file='tree' name='xmlDocPtr'/>
+      <typedef line='214' file='tree' name='xmlNsPtr'/>
+      <function line='97' file='xpath' name='xmlXPathNewContext'/>
+      <typedef line='202' file='tree' name='xmlNodePtr'/>
       <function line='45' file='parser' name='xmlCleanupParser'/>
       <macro line='39' file='xmlversion' name='LIBXML_TEST_VERSION'/>
-      <typedef line='79' file='xpath' name='xmlXPathContextPtr'/>
-      <function line='122' file='xpath' name='xmlXPathFreeContext'/>
+      <typedef line='83' file='xpath' name='xmlXPathContextPtr'/>
+      <function line='126' file='xpath' name='xmlXPathFreeContext'/>
       <function line='35' file='parser' name='xmlInitParser'/>
-      <function line='148' file='parser' name='xmlStrdup'/>
-      <function line='123' file='tree' name='xmlFreeDoc'/>
-      <function line='172' file='parser' name='xmlStrchr'/>
-      <typedef line='198' file='tree' name='xmlNodePtr'/>
-      <function line='86' file='parser' name='xmlParseFile'/>
-      <enum line='209' file='tree' name='XML_NAMESPACE_DECL'/>
+      <function line='152' file='xmlstring' name='xmlStrdup'/>
+      <function line='127' file='tree' name='xmlFreeDoc'/>
+      <function line='176' file='xmlstring' name='xmlStrchr'/>
+      <variable line='189' file='globals' name='xmlFree'/>
+      <function line='90' file='parser' name='xmlParseFile'/>
+      <enum line='213' file='tree' name='XML_NAMESPACE_DECL'/>
     </uses>
   </example>
   <example filename='parse1.c'>
@@ -49,9 +51,10 @@
     <uses>
       <function line='50' file='parser' name='xmlCleanupParser'/>
       <macro line='45' file='xmlversion' name='LIBXML_TEST_VERSION'/>
+      <typedef line='24' file='tree' name='xmlDocPtr'/>
       <function line='31' file='tree' name='xmlFreeDoc'/>
       <function line='26' file='parser' name='xmlReadFile'/>
-      <typedef line='24' file='tree' name='xmlDocPtr'/>
+      <function line='54' file='xmlmemory' name='xmlMemoryDump'/>
     </uses>
   </example>
   <example filename='parse2.c'>
@@ -76,6 +79,7 @@
       <function line='35' file='parser' name='xmlCtxtReadFile'/>
       <function line='44' file='tree' name='xmlFreeDoc'/>
       <typedef line='26' file='tree' name='xmlDocPtr'/>
+      <function line='70' file='xmlmemory' name='xmlMemoryDump'/>
     </uses>
   </example>
   <example filename='tree1.c'>
@@ -113,6 +117,7 @@
     </includes>
     <uses>
       <function line='73' file='tree' name='xmlNewText'/>
+      <function line='108' file='xmlmemory' name='xmlMemoryDump'/>
       <function line='94' file='tree' name='xmlSaveFormatFileEnc'/>
       <function line='76' file='tree' name='xmlAddChild'/>
       <function line='39' file='tree' name='xmlDocSetRootElement'/>
@@ -139,36 +144,39 @@
       <include>&lt;libxml/xmlwriter.h&gt;</include>
     </includes>
     <uses>
-      <function line='1075' file='xmlwriter' name='xmlTextWriterEndElement'/>
-      <function line='880' file='xmlwriter' name='xmlTextWriterStartDocument'/>
-      <function line='1085' file='xmlwriter' name='xmlTextWriterEndDocument'/>
-      <function line='925' file='xmlwriter' name='xmlTextWriterWriteFormatComment'/>
-      <function line='890' file='xmlwriter' name='xmlTextWriterWriteComment'/>
-      <variable line='1147' file='globals' name='xmlRealloc'/>
-      <function line='1037' file='xmlwriter' name='xmlTextWriterWriteFormatElement'/>
-      <function line='1120' file='encoding' name='xmlFindCharEncodingHandler'/>
-      <typedef line='1115' file='encoding' name='xmlCharEncodingHandlerPtr'/>
-      <function line='871' file='xmlwriter' name='xmlNewTextWriterTree'/>
-      <function line='58' file='xmlwriter' name='xmlNewTextWriterFilename'/>
-      <function line='1095' file='tree' name='xmlFreeDoc'/>
-      <typedef line='848' file='tree' name='xmlNodePtr'/>
-      <typedef line='847' file='tree' name='xmlDocPtr'/>
-      <typedef line='320' file='tree' name='xmlBufferPtr'/>
-      <function line='603' file='xmlwriter' name='xmlNewTextWriterDoc'/>
-      <function line='861' file='tree' name='xmlNewDocNode'/>
-      <function line='1093' file='tree' name='xmlSaveFileEnc'/>
-      <macro line='852' file='parser' name='XML_DEFAULT_VERSION'/>
-      <function line='333' file='xmlwriter' name='xmlNewTextWriterMemory'/>
-      <variable line='1144' file='globals' name='xmlFree'/>
-      <function line='868' file='tree' name='xmlDocSetRootElement'/>
-      <function line='1091' file='xmlwriter' name='xmlFreeTextWriter'/>
-      <function line='1060' file='xmlwriter' name='xmlTextWriterStartElement'/>
-      <variable line='1130' file='globals' name='xmlMalloc'/>
-      <function line='325' file='tree' name='xmlBufferCreate'/>
-      <typedef line='846' file='xmlwriter' name='xmlTextWriterPtr'/>
-      <function line='1067' file='xmlwriter' name='xmlTextWriterWriteElement'/>
-      <function line='916' file='xmlwriter' name='xmlTextWriterWriteAttribute'/>
-      <function line='852' file='tree' name='xmlNewDoc'/>
+      <function line='1090' file='xmlwriter' name='xmlTextWriterEndElement'/>
+      <function line='895' file='xmlwriter' name='xmlTextWriterStartDocument'/>
+      <function line='1100' file='xmlwriter' name='xmlTextWriterEndDocument'/>
+      <function line='940' file='xmlwriter' name='xmlTextWriterWriteFormatComment'/>
+      <function line='905' file='xmlwriter' name='xmlTextWriterWriteComment'/>
+      <function line='52' file='parser' name='xmlCleanupParser'/>
+      <variable line='1145' file='globals' name='xmlMalloc'/>
+      <function line='1052' file='xmlwriter' name='xmlTextWriterWriteFormatElement'/>
+      <function line='1135' file='encoding' name='xmlFindCharEncodingHandler'/>
+      <typedef line='1130' file='encoding' name='xmlCharEncodingHandlerPtr'/>
+      <function line='886' file='xmlwriter' name='xmlNewTextWriterTree'/>
+      <function line='73' file='xmlwriter' name='xmlNewTextWriterFilename'/>
+      <function line='1110' file='tree' name='xmlFreeDoc'/>
+      <typedef line='863' file='tree' name='xmlNodePtr'/>
+      <typedef line='862' file='tree' name='xmlDocPtr'/>
+      <typedef line='335' file='tree' name='xmlBufferPtr'/>
+      <function line='618' file='xmlwriter' name='xmlNewTextWriterDoc'/>
+      <function line='876' file='tree' name='xmlNewDocNode'/>
+      <function line='1108' file='tree' name='xmlSaveFileEnc'/>
+      <function line='56' file='xmlmemory' name='xmlMemoryDump'/>
+      <macro line='867' file='parser' name='XML_DEFAULT_VERSION'/>
+      <function line='348' file='xmlwriter' name='xmlNewTextWriterMemory'/>
+      <variable line='1159' file='globals' name='xmlFree'/>
+      <function line='883' file='tree' name='xmlDocSetRootElement'/>
+      <function line='1106' file='xmlwriter' name='xmlFreeTextWriter'/>
+      <function line='1075' file='xmlwriter' name='xmlTextWriterStartElement'/>
+      <macro line='38' file='xmlversion' name='LIBXML_TEST_VERSION'/>
+      <function line='340' file='tree' name='xmlBufferCreate'/>
+      <typedef line='861' file='xmlwriter' name='xmlTextWriterPtr'/>
+      <function line='1082' file='xmlwriter' name='xmlTextWriterWriteElement'/>
+      <function line='931' file='xmlwriter' name='xmlTextWriterWriteAttribute'/>
+      <variable line='1162' file='globals' name='xmlRealloc'/>
+      <function line='867' file='tree' name='xmlNewDoc'/>
     </uses>
   </example>
   <example filename='reader1.c'>
@@ -183,14 +191,13 @@
       <include>&lt;libxml/xmlreader.h&gt;</include>
     </includes>
     <uses>
-      <function line='40' file='parser' name='xmlStrlen'/>
-      <function line='90' file='parser' name='xmlCleanupParser'/>
+      <function line='40' file='xmlstring' name='xmlStrlen'/>
       <function line='33' file='xmlreader' name='xmlTextReaderNodeType'/>
       <typedef line='55' file='xmlreader' name='xmlTextReaderPtr'/>
+      <function line='94' file='xmlmemory' name='xmlMemoryDump'/>
       <function line='29' file='xmlreader' name='xmlTextReaderConstValue'/>
       <function line='32' file='xmlreader' name='xmlTextReaderDepth'/>
       <function line='65' file='xmlreader' name='xmlFreeTextReader'/>
-      <macro line='85' file='xmlversion' name='LIBXML_TEST_VERSION'/>
       <function line='25' file='xmlreader' name='xmlTextReaderConstName'/>
       <function line='36' file='xmlreader' name='xmlTextReaderHasValue'/>
       <function line='63' file='xmlreader' name='xmlTextReaderRead'/>
@@ -210,7 +217,7 @@
       <include>&lt;libxml/xmlreader.h&gt;</include>
     </includes>
     <uses>
-      <function line='41' file='parser' name='xmlStrlen'/>
+      <function line='41' file='xmlstring' name='xmlStrlen'/>
       <function line='34' file='xmlreader' name='xmlTextReaderNodeType'/>
       <typedef line='56' file='xmlreader' name='xmlTextReaderPtr'/>
       <function line='30' file='xmlreader' name='xmlTextReaderConstValue'/>
@@ -249,6 +256,28 @@
       <typedef line='72' file='tree' name='xmlDocPtr'/>
     </uses>
   </example>
+  <example filename='io1.c'>
+    <synopsis>Example of custom Input/Output</synopsis>
+    <purpose>Demonstrate the use of xmlRegisterInputCallbacks to build a custom I/O layer, this is used in an XInclude method context to show how dynamic document can be built in a clean way.</purpose>
+    <usage>io1</usage>
+    <test>io1 &gt; io1.tmp ; diff io1.tmp io1.res ; rm -f io1.tmp</test>
+    <author>Daniel Veillard</author>
+    <copy>see Copyright for the status of this software. </copy>
+    <section>InputOutput</section>
+    <includes>
+      <include>&lt;libxml/parser.h&gt;</include>
+      <include>&lt;libxml/xinclude.h&gt;</include>
+      <include>&lt;libxml/tree.h&gt;</include>
+      <include>&lt;libxml/xmlIO.h&gt;</include>
+    </includes>
+    <uses>
+      <function line='139' file='tree' name='xmlDocDump'/>
+      <function line='132' file='xinclude' name='xmlXIncludeProcess'/>
+      <function line='116' file='xmlIO' name='xmlRegisterInputCallbacks'/>
+      <function line='123' file='parser' name='xmlReadMemory'/>
+      <typedef line='104' file='tree' name='xmlDocPtr'/>
+    </uses>
+  </example>
   <symbols>
     <symbol name='LIBXML_TEST_VERSION'>
       <ref filename='xpath1.c'/>
@@ -256,7 +285,7 @@
       <ref filename='parse2.c'/>
       <ref filename='tree1.c'/>
       <ref filename='tree2.c'/>
-      <ref filename='reader1.c'/>
+      <ref filename='testWriter.c'/>
     </symbol>
     <symbol name='XML_DEFAULT_VERSION'>
       <ref filename='testWriter.c'/>
@@ -296,7 +325,7 @@
       <ref filename='parse2.c'/>
       <ref filename='tree1.c'/>
       <ref filename='tree2.c'/>
-      <ref filename='reader1.c'/>
+      <ref filename='testWriter.c'/>
     </symbol>
     <symbol name='xmlCreateIntSubset'>
       <ref filename='tree2.c'/>
@@ -306,6 +335,7 @@
     </symbol>
     <symbol name='xmlDocDump'>
       <ref filename='reader3.c'/>
+      <ref filename='io1.c'/>
     </symbol>
     <symbol name='xmlDocGetRootElement'>
       <ref filename='tree1.c'/>
@@ -316,6 +346,7 @@
       <ref filename='parse2.c'/>
       <ref filename='testWriter.c'/>
       <ref filename='reader3.c'/>
+      <ref filename='io1.c'/>
     </symbol>
     <symbol name='xmlDocSetRootElement'>
       <ref filename='tree2.c'/>
@@ -325,6 +356,7 @@
       <ref filename='testWriter.c'/>
     </symbol>
     <symbol name='xmlFree'>
+      <ref filename='xpath1.c'/>
       <ref filename='testWriter.c'/>
     </symbol>
     <symbol name='xmlFreeDoc'>
@@ -352,6 +384,14 @@
     <symbol name='xmlMalloc'>
       <ref filename='testWriter.c'/>
     </symbol>
+    <symbol name='xmlMemoryDump'>
+      <ref filename='xpath1.c'/>
+      <ref filename='parse1.c'/>
+      <ref filename='parse2.c'/>
+      <ref filename='tree2.c'/>
+      <ref filename='testWriter.c'/>
+      <ref filename='reader1.c'/>
+    </symbol>
     <symbol name='xmlNewChild'>
       <ref filename='tree2.c'/>
     </symbol>
@@ -403,6 +443,9 @@
     <symbol name='xmlReadFile'>
       <ref filename='parse1.c'/>
     </symbol>
+    <symbol name='xmlReadMemory'>
+      <ref filename='io1.c'/>
+    </symbol>
     <symbol name='xmlReaderForFile'>
       <ref filename='reader1.c'/>
       <ref filename='reader2.c'/>
@@ -411,6 +454,9 @@
     <symbol name='xmlRealloc'>
       <ref filename='testWriter.c'/>
     </symbol>
+    <symbol name='xmlRegisterInputCallbacks'>
+      <ref filename='io1.c'/>
+    </symbol>
     <symbol name='xmlSaveFileEnc'>
       <ref filename='testWriter.c'/>
     </symbol>
@@ -500,6 +546,9 @@
     <symbol name='xmlTextWriterWriteFormatElement'>
       <ref filename='testWriter.c'/>
     </symbol>
+    <symbol name='xmlXIncludeProcess'>
+      <ref filename='io1.c'/>
+    </symbol>
     <symbol name='xmlXPathContextPtr'>
       <ref filename='xpath1.c'/>
     </symbol>
@@ -523,6 +572,9 @@
     </symbol>
   </symbols>
   <sections>
+    <section name='InputOutput'>
+      <example filename='io1.c'/>
+    </section>
     <section name='Parsing'>
       <example filename='parse1.c'/>
       <example filename='parse2.c'/>
diff --git a/doc/examples/index.html b/doc/examples/index.html
index e2520f5..728eb71 100644
--- a/doc/examples/index.html
+++ b/doc/examples/index.html
@@ -7,5 +7,5 @@
 H2 {font-family: Verdana,Arial,Helvetica}
 H3 {font-family: Verdana,Arial,Helvetica}
 A:link, A:visited, A:active { text-decoration: underline }
-</style><title>Libxml2 set of examples</title></head><body bgcolor="#8b7765" text="#000000" link="#000000" vlink="#000000"><table border="0" width="100%" cellpadding="5" cellspacing="0" align="center"><tr><td width="120"><a href="http://swpat.ffii.org/"><img src="../epatents.png" alt="Action against software patents" /></a></td><td width="180"><a href="http://www.gnome.org/"><img src="../gnome2.png" alt="Gnome2 Logo" /></a><a href="http://www.w3.org/Status"><img src="../w3c.png" alt="W3C Logo" /></a><a href="http://www.redhat.com/"><img src="../redhat.gif" alt="Red Hat Logo" /></a><div align="left"><a href="http://xmlsoft.org/"><img src="../Libxml2-Logo-180x168.gif" alt="Made with Libxml2 Logo" /></a></div></td><td><table border="0" width="90%" cellpadding="2" cellspacing="0" align="center" bgcolor="#000000"><tr><td><table width="100%" border="0" cellspacing="1" cellpadding="3" bgcolor="#fffacd"><tr><td align="center"><h1></h1><h2>Libxml2 set of examples</h2></td></tr></table></td></tr></table></td></tr></table><table border="0" cellpadding="4" cellspacing="0" width="100%" align="center"><tr><td bgcolor="#8b7765"><table border="0" cellspacing="0" cellpadding="2" width="100%"><tr><td valign="top" width="200" bgcolor="#8b7765"><table border="0" cellspacing="0" cellpadding="1" width="100%" bgcolor="#000000"><tr><td><table width="100%" border="0" cellspacing="1" cellpadding="3"><tr><td colspan="1" bgcolor="#eecfa1" align="center"><center><b>Examples Menu</b></center></td></tr><tr><td bgcolor="#fffacd"><form action="../search.php" enctype="application/x-www-form-urlencoded" method="get"><input name="query" type="text" size="20" value="" /><input name="submit" type="submit" value="Search ..." /></form><ul><li><a href="../index.html">Home</a></li><li><a style="font-weight:bold" href="../docs.html">Developer Menu</a></li><li><a style="font-weight:bold" href="../html/index.html">API Menu</a></li><li><a href="#Parsing">Parsing Examples</a></li><li><a href="#Tree">Tree Examples</a></li><li><a href="#XPath">XPath Examples</a></li><li><a href="#xmlReader">xmlReader Examples</a></li><li><a href="#xmlWriter">xmlWriter Examples</a></li><li><a href="../guidelines.html">XML Guidelines</a></li></ul></td></tr></table><table width="100%" border="0" cellspacing="1" cellpadding="3"><tr><td colspan="1" bgcolor="#eecfa1" align="center"><center><b>Related links</b></center></td></tr><tr><td bgcolor="#fffacd"><ul><li><a href="http://mail.gnome.org/archives/xml/">Mail archive</a></li><li><a href="http://xmlsoft.org/XSLT/">XSLT libxslt</a></li><li><a href="http://phd.cs.unibo.it/gdome2/">DOM gdome2</a></li><li><a href="http://www.aleksey.com/xmlsec/">XML-DSig xmlsec</a></li><li><a href="ftp://xmlsoft.org/">FTP</a></li><li><a href="http://www.zlatkovic.com/projects/libxml/">Windows binaries</a></li><li><a href="http://garypennington.net/libxml2/">Solaris binaries</a></li><li><a href="http://www.zveno.com/open_source/libxml2xslt.html">MacOsX binaries</a></li><li><a href="http://sourceforge.net/projects/libxml2-pas/">Pascal bindings</a></li><li><a href="http://bugzilla.gnome.org/buglist.cgi?product=libxml2">Bug Tracker</a></li></ul></td></tr></table></td></tr></table></td><td valign="top" bgcolor="#8b7765"><table border="0" cellspacing="0" cellpadding="1" width="100%"><tr><td><table border="0" cellspacing="0" cellpadding="1" width="100%" bgcolor="#000000"><tr><td><table border="0" cellpadding="3" cellspacing="1" width="100%"><tr><td bgcolor="#fffacd"><p> The examples are stored per section depending on the main focus
-    of the example:</p><ul><li><p><a href="#XPath">XPath</a> :</p><ul><li><a href="#xpath1.c">xpath1.c</a>: Evaluate XPath expression and prints result node set.</li></ul></li><li><p><a href="#xmlWriter">xmlWriter</a> :</p><ul><li><a href="#testWriter.c">testWriter.c</a>: use various APIs for the xmlWriter</li></ul></li><li><p><a href="#Parsing">Parsing</a> :</p><ul><li><a href="#parse1.c">parse1.c</a>: Parse an XML file to a tree and free it</li><li><a href="#parse2.c">parse2.c</a>: Parse and validate an XML file to a tree and free the result</li></ul></li><li><p><a href="#Tree">Tree</a> :</p><ul><li><a href="#tree1.c">tree1.c</a>: Navigates a tree to print element names</li><li><a href="#tree2.c">tree2.c</a>: Creates a tree</li></ul></li><li><p><a href="#xmlReader">xmlReader</a> :</p><ul><li><a href="#reader1.c">reader1.c</a>: Parse an XML file with an xmlReader</li><li><a href="#reader2.c">reader2.c</a>: Parse and validate an XML file with an xmlReader</li><li><a href="#reader3.c">reader3.c</a>: Show how to extract subdocuments with xmlReader</li></ul></li></ul><h2><a name="Parsing" id="Parsing"></a>Parsing Examples</h2><h3><a name="parse1.c" href="parse1.c" id="parse1.c">parse1.c</a>: Parse an XML file to a tree and free it</h3><p>Demonstrate the use of xmlReadFile() to read an XML file into a tree and and xmlFreeDoc() to free the resulting tree</p><p>Includes:</p><ul><li><a href="../html/libxml-tree.html">&lt;libxml/tree.h&gt;</a></li><li><a href="../html/libxml-parser.html">&lt;libxml/parser.h&gt;</a></li></ul><p>Uses:</p><ul><li> line 24: Type <a href="../html/libxml-tree.html#xmlDocPtr">xmlDocPtr</a> from tree.h</li><li> line 26: Function <a href="../html/libxml-parser.html#xmlReadFile">xmlReadFile</a> from parser.h</li><li> line 31: Function <a href="../html/libxml-tree.html#xmlFreeDoc">xmlFreeDoc</a> from tree.h</li><li> line 45: Macro <a href="../html/libxml-xmlversion.html#LIBXML_TEST_VERSION">LIBXML_TEST_VERSION</a> from xmlversion.h</li><li> line 50: Function <a href="../html/libxml-parser.html#xmlCleanupParser">xmlCleanupParser</a> from parser.h</li></ul><p>Usage:</p><p>parse1 test1.xml</p><p>Author: Daniel Veillard</p><h3><a name="parse2.c" href="parse2.c" id="parse2.c">parse2.c</a>: Parse and validate an XML file to a tree and free the result</h3><p>Create a parser context for an XML file, then parse and validate the file, creating a tree, check the validation result and xmlFreeDoc() to free the resulting tree.</p><p>Includes:</p><ul><li><a href="../html/libxml-tree.html">&lt;libxml/tree.h&gt;</a></li><li><a href="../html/libxml-parser.html">&lt;libxml/parser.h&gt;</a></li></ul><p>Uses:</p><ul><li> line 25: Type <a href="../html/libxml-tree.html#xmlParserCtxtPtr">xmlParserCtxtPtr</a> from tree.h</li><li> line 26: Type <a href="../html/libxml-tree.html#xmlDocPtr">xmlDocPtr</a> from tree.h</li><li> line 29: Function <a href="../html/libxml-parser.html#xmlNewParserCtxt">xmlNewParserCtxt</a> from parser.h</li><li> line 35: Function <a href="../html/libxml-parser.html#xmlCtxtReadFile">xmlCtxtReadFile</a> from parser.h</li><li> line 44: Function <a href="../html/libxml-tree.html#xmlFreeDoc">xmlFreeDoc</a> from tree.h</li><li> line 47: Function <a href="../html/libxml-parser.html#xmlFreeParserCtxt">xmlFreeParserCtxt</a> from parser.h</li><li> line 61: Macro <a href="../html/libxml-xmlversion.html#LIBXML_TEST_VERSION">LIBXML_TEST_VERSION</a> from xmlversion.h</li><li> line 66: Function <a href="../html/libxml-parser.html#xmlCleanupParser">xmlCleanupParser</a> from parser.h</li></ul><p>Usage:</p><p>parse2 test2.xml</p><p>Author: Daniel Veillard</p><h2><a name="Tree" id="Tree"></a>Tree Examples</h2><h3><a name="tree1.c" href="tree1.c" id="tree1.c">tree1.c</a>: Navigates a tree to print element names</h3><p>Parse a file to a tree, use xmlDocGetRootElement() to get the root element, then walk the document and print all the element name in document order.</p><p>Includes:</p><ul><li><a href="../html/libxml-tree.html">&lt;libxml/tree.h&gt;</a></li><li><a href="../html/libxml-parser.html">&lt;libxml/parser.h&gt;</a></li></ul><p>Uses:</p><ul><li> line 65: Macro <a href="../html/libxml-xmlversion.html#LIBXML_TEST_VERSION">LIBXML_TEST_VERSION</a> from xmlversion.h</li><li> line 65: Function <a href="../html/libxml-parser.html#xmlParseFile">xmlParseFile</a> from parser.h</li><li> line 72: Function <a href="../html/libxml-tree.html#xmlDocGetRootElement">xmlDocGetRootElement</a> from tree.h</li><li> line 77: Function <a href="../html/libxml-tree.html#xmlFreeDoc">xmlFreeDoc</a> from tree.h</li><li> line 83: Function <a href="../html/libxml-parser.html#xmlCleanupParser">xmlCleanupParser</a> from parser.h</li></ul><p>Usage:</p><p>tree1 filename_or_URL</p><p>Author: Dodji Seketeli</p><h3><a name="tree2.c" href="tree2.c" id="tree2.c">tree2.c</a>: Creates a tree</h3><p>Shows how to create document, nodes and dump it to stdout or file.</p><p>Includes:</p><ul><li><a href="../html/libxml-tree.html">&lt;libxml/tree.h&gt;</a></li><li><a href="../html/libxml-parser.html">&lt;libxml/parser.h&gt;</a></li></ul><p>Uses:</p><ul><li> line 32: Macro <a href="../html/libxml-xmlversion.html#LIBXML_TEST_VERSION">LIBXML_TEST_VERSION</a> from xmlversion.h</li><li> line 37: Function <a href="../html/libxml-tree.html#xmlNewDoc">xmlNewDoc</a> from tree.h</li><li> line 39: Function <a href="../html/libxml-tree.html#xmlDocSetRootElement">xmlDocSetRootElement</a> from tree.h</li><li> line 44: Function <a href="../html/libxml-tree.html#xmlCreateIntSubset">xmlCreateIntSubset</a> from tree.h</li><li> line 72: Function <a href="../html/libxml-tree.html#xmlNewNode">xmlNewNode</a> from tree.h</li><li> line 73: Function <a href="../html/libxml-tree.html#xmlNewText">xmlNewText</a> from tree.h</li><li> line 76: Function <a href="../html/libxml-tree.html#xmlAddChild">xmlAddChild</a> from tree.h</li><li> line 86: Function <a href="../html/libxml-tree.html#xmlNewChild">xmlNewChild</a> from tree.h</li><li> line 87: Function <a href="../html/libxml-tree.html#xmlNewProp">xmlNewProp</a> from tree.h</li><li> line 94: Function <a href="../html/libxml-tree.html#xmlSaveFormatFileEnc">xmlSaveFormatFileEnc</a> from tree.h</li><li> line 97: Function <a href="../html/libxml-tree.html#xmlFreeDoc">xmlFreeDoc</a> from tree.h</li><li> line 103: Function <a href="../html/libxml-parser.html#xmlCleanupParser">xmlCleanupParser</a> from parser.h</li></ul><p>Usage:</p><p>tree2 &lt;filename&gt;  -Default output: stdout</p><p>Author: Lucas Brasilino &lt;brasilino@recife.pe.gov.br&gt;</p><h2><a name="XPath" id="XPath"></a>XPath Examples</h2><h3><a name="xpath1.c" href="xpath1.c" id="xpath1.c">xpath1.c</a>: Evaluate XPath expression and prints result node set.</h3><p>Shows how to evaluate XPath expression and register known namespaces in XPath context.</p><p>Includes:</p><ul><li><a href="../html/libxml-xpath.html">&lt;libxml/xpath.h&gt;</a></li><li><a href="../html/libxml-parser.html">&lt;libxml/parser.h&gt;</a></li><li><a href="../html/libxml-xpathInternals.html">&lt;libxml/xpathInternals.h&gt;</a></li><li><a href="../html/libxml-tree.html">&lt;libxml/tree.h&gt;</a></li></ul><p>Uses:</p><ul><li> line 35: Function <a href="../html/libxml-parser.html#xmlInitParser">xmlInitParser</a> from parser.h</li><li> line 39: Macro <a href="../html/libxml-xmlversion.html#LIBXML_TEST_VERSION">LIBXML_TEST_VERSION</a> from xmlversion.h</li><li> line 45: Function <a href="../html/libxml-parser.html#xmlCleanupParser">xmlCleanupParser</a> from parser.h</li><li> line 78: Type <a href="../html/libxml-tree.html#xmlDocPtr">xmlDocPtr</a> from tree.h</li><li> line 79: Type <a href="../html/libxml-xpath.html#xmlXPathContextPtr">xmlXPathContextPtr</a> from xpath.h</li><li> line 80: Type <a href="../html/libxml-xpath.html#xmlXPathObjectPtr">xmlXPathObjectPtr</a> from xpath.h</li><li> line 86: Function <a href="../html/libxml-parser.html#xmlParseFile">xmlParseFile</a> from parser.h</li><li> line 93: Function <a href="../html/libxml-xpath.html#xmlXPathNewContext">xmlXPathNewContext</a> from xpath.h</li><li> line 109: Function <a href="../html/libxml-xpath.html#xmlXPathEvalExpression">xmlXPathEvalExpression</a> from xpath.h</li><li> line 121: Function <a href="../html/libxml-xpath.html#xmlXPathFreeObject">xmlXPathFreeObject</a> from xpath.h</li><li> line 122: Function <a href="../html/libxml-xpath.html#xmlXPathFreeContext">xmlXPathFreeContext</a> from xpath.h</li><li> line 123: Function <a href="../html/libxml-tree.html#xmlFreeDoc">xmlFreeDoc</a> from tree.h</li><li> line 148: Function <a href="../html/libxml-parser.html#xmlStrdup">xmlStrdup</a> from parser.h</li><li> line 172: Function <a href="../html/libxml-parser.html#xmlStrchr">xmlStrchr</a> from parser.h</li><li> line 178: Function <a href="../html/libxml-xpathInternals.html#xmlXPathRegisterNs">xmlXPathRegisterNs</a> from xpathInternals.h</li><li> line 198: Type <a href="../html/libxml-tree.html#xmlNodePtr">xmlNodePtr</a> from tree.h</li><li> line 210: Type <a href="../html/libxml-tree.html#xmlNsPtr">xmlNsPtr</a> from tree.h</li></ul><p>Usage:</p><p>xpath1 &lt;xml-file&gt; &lt;xpath-expr&gt; [&lt;known-ns-list&gt;]</p><p>Author: Aleksey Sanin</p><h2><a name="xmlReader" id="xmlReader"></a>xmlReader Examples</h2><h3><a name="reader1.c" href="reader1.c" id="reader1.c">reader1.c</a>: Parse an XML file with an xmlReader</h3><p>Demonstrate the use of xmlReaderForFile() to parse an XML file and dump the informations about the nodes found in the process</p><p>Includes:</p><ul><li><a href="../html/libxml-xmlreader.html">&lt;libxml/xmlreader.h&gt;</a></li></ul><p>Uses:</p><ul><li> line 25: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderConstName">xmlTextReaderConstName</a> from xmlreader.h</li><li> line 29: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderConstValue">xmlTextReaderConstValue</a> from xmlreader.h</li><li> line 32: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderDepth">xmlTextReaderDepth</a> from xmlreader.h</li><li> line 33: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderNodeType">xmlTextReaderNodeType</a> from xmlreader.h</li><li> line 35: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderIsEmptyElement">xmlTextReaderIsEmptyElement</a> from xmlreader.h</li><li> line 36: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderHasValue">xmlTextReaderHasValue</a> from xmlreader.h</li><li> line 40: Function <a href="../html/libxml-parser.html#xmlStrlen">xmlStrlen</a> from parser.h</li><li> line 55: Type <a href="../html/libxml-xmlreader.html#xmlTextReaderPtr">xmlTextReaderPtr</a> from xmlreader.h</li><li> line 58: Function <a href="../html/libxml-xmlreader.html#xmlReaderForFile">xmlReaderForFile</a> from xmlreader.h</li><li> line 63: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderRead">xmlTextReaderRead</a> from xmlreader.h</li><li> line 65: Function <a href="../html/libxml-xmlreader.html#xmlFreeTextReader">xmlFreeTextReader</a> from xmlreader.h</li><li> line 85: Macro <a href="../html/libxml-xmlversion.html#LIBXML_TEST_VERSION">LIBXML_TEST_VERSION</a> from xmlversion.h</li><li> line 90: Function <a href="../html/libxml-parser.html#xmlCleanupParser">xmlCleanupParser</a> from parser.h</li></ul><p>Usage:</p><p>reader1 &lt;filename&gt;</p><p>Author: Daniel Veillard</p><h3><a name="reader2.c" href="reader2.c" id="reader2.c">reader2.c</a>: Parse and validate an XML file with an xmlReader</h3><p>Demonstrate the use of xmlReaderForFile() to parse an XML file validating the content in the process and activating options like entities substitution, and DTD attributes defaulting</p><p>Includes:</p><ul><li><a href="../html/libxml-xmlreader.html">&lt;libxml/xmlreader.h&gt;</a></li></ul><p>Uses:</p><ul><li> line 26: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderConstName">xmlTextReaderConstName</a> from xmlreader.h</li><li> line 30: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderConstValue">xmlTextReaderConstValue</a> from xmlreader.h</li><li> line 33: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderDepth">xmlTextReaderDepth</a> from xmlreader.h</li><li> line 34: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderNodeType">xmlTextReaderNodeType</a> from xmlreader.h</li><li> line 36: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderIsEmptyElement">xmlTextReaderIsEmptyElement</a> from xmlreader.h</li><li> line 37: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderHasValue">xmlTextReaderHasValue</a> from xmlreader.h</li><li> line 41: Function <a href="../html/libxml-parser.html#xmlStrlen">xmlStrlen</a> from parser.h</li><li> line 56: Type <a href="../html/libxml-xmlreader.html#xmlTextReaderPtr">xmlTextReaderPtr</a> from xmlreader.h</li><li> line 64: Function <a href="../html/libxml-xmlreader.html#xmlReaderForFile">xmlReaderForFile</a> from xmlreader.h</li><li> line 72: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderRead">xmlTextReaderRead</a> from xmlreader.h</li><li> line 77: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderIsValid">xmlTextReaderIsValid</a> from xmlreader.h</li><li> line 80: Function <a href="../html/libxml-xmlreader.html#xmlFreeTextReader">xmlFreeTextReader</a> from xmlreader.h</li></ul><p>Usage:</p><p>reader2 &lt;valid_xml_filename&gt;</p><p>Author: Daniel Veillard</p><h3><a name="reader3.c" href="reader3.c" id="reader3.c">reader3.c</a>: Show how to extract subdocuments with xmlReader</h3><p>Demonstrate the use of xmlTextReaderPreservePattern() to parse an XML file with the xmlReader while collecting only some subparts of the document</p><p>Includes:</p><ul><li><a href="../html/libxml-xmlreader.html">&lt;libxml/xmlreader.h&gt;</a></li></ul><p>Uses:</p><ul><li> line 27: Type <a href="../html/libxml-xmlreader.html#xmlTextReaderPtr">xmlTextReaderPtr</a> from xmlreader.h</li><li> line 33: Function <a href="../html/libxml-xmlreader.html#xmlReaderForFile">xmlReaderForFile</a> from xmlreader.h</li><li> line 38: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderPreservePattern">xmlTextReaderPreservePattern</a> from xmlreader.h</li><li> line 47: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderRead">xmlTextReaderRead</a> from xmlreader.h</li><li> line 57: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderCurrentDoc">xmlTextReaderCurrentDoc</a> from xmlreader.h</li><li> line 61: Function <a href="../html/libxml-xmlreader.html#xmlFreeTextReader">xmlFreeTextReader</a> from xmlreader.h</li><li> line 72: Type <a href="../html/libxml-tree.html#xmlDocPtr">xmlDocPtr</a> from tree.h</li><li> line 91: Function <a href="../html/libxml-tree.html#xmlDocDump">xmlDocDump</a> from tree.h</li></ul><p>Usage:</p><p>reader3</p><p>Author: Daniel Veillard</p><h2><a name="xmlWriter" id="xmlWriter"></a>xmlWriter Examples</h2><h3><a name="testWriter.c" href="testWriter.c" id="testWriter.c">testWriter.c</a>: use various APIs for the xmlWriter</h3><p>tests a number of APIs for the xmlWriter, especially the various methods to write to a filename, to a memory buffer, to a new document, or to a subtree. It shows how to do encoding string conversions too. The resulting documents are then serialized.</p><p>Includes:</p><ul><li><a href="../html/libxml-encoding.html">&lt;libxml/encoding.h&gt;</a></li><li><a href="../html/libxml-xmlwriter.html">&lt;libxml/xmlwriter.h&gt;</a></li></ul><p>Uses:</p><ul><li> line 58: Function <a href="../html/libxml-xmlwriter.html#xmlNewTextWriterFilename">xmlNewTextWriterFilename</a> from xmlwriter.h</li><li> line 320: Type <a href="../html/libxml-tree.html#xmlBufferPtr">xmlBufferPtr</a> from tree.h</li><li> line 325: Function <a href="../html/libxml-tree.html#xmlBufferCreate">xmlBufferCreate</a> from tree.h</li><li> line 333: Function <a href="../html/libxml-xmlwriter.html#xmlNewTextWriterMemory">xmlNewTextWriterMemory</a> from xmlwriter.h</li><li> line 603: Function <a href="../html/libxml-xmlwriter.html#xmlNewTextWriterDoc">xmlNewTextWriterDoc</a> from xmlwriter.h</li><li> line 846: Type <a href="../html/libxml-xmlwriter.html#xmlTextWriterPtr">xmlTextWriterPtr</a> from xmlwriter.h</li><li> line 847: Type <a href="../html/libxml-tree.html#xmlDocPtr">xmlDocPtr</a> from tree.h</li><li> line 848: Type <a href="../html/libxml-tree.html#xmlNodePtr">xmlNodePtr</a> from tree.h</li><li> line 852: Macro <a href="../html/libxml-parser.html#XML_DEFAULT_VERSION">XML_DEFAULT_VERSION</a> from parser.h</li><li> line 852: Function <a href="../html/libxml-tree.html#xmlNewDoc">xmlNewDoc</a> from tree.h</li><li> line 861: Function <a href="../html/libxml-tree.html#xmlNewDocNode">xmlNewDocNode</a> from tree.h</li><li> line 868: Function <a href="../html/libxml-tree.html#xmlDocSetRootElement">xmlDocSetRootElement</a> from tree.h</li><li> line 871: Function <a href="../html/libxml-xmlwriter.html#xmlNewTextWriterTree">xmlNewTextWriterTree</a> from xmlwriter.h</li><li> line 880: Function <a href="../html/libxml-xmlwriter.html#xmlTextWriterStartDocument">xmlTextWriterStartDocument</a> from xmlwriter.h</li><li> line 890: Function <a href="../html/libxml-xmlwriter.html#xmlTextWriterWriteComment">xmlTextWriterWriteComment</a> from xmlwriter.h</li><li> line 916: Function <a href="../html/libxml-xmlwriter.html#xmlTextWriterWriteAttribute">xmlTextWriterWriteAttribute</a> from xmlwriter.h</li><li> line 925: Function <a href="../html/libxml-xmlwriter.html#xmlTextWriterWriteFormatComment">xmlTextWriterWriteFormatComment</a> from xmlwriter.h</li><li> line 1037: Function <a href="../html/libxml-xmlwriter.html#xmlTextWriterWriteFormatElement">xmlTextWriterWriteFormatElement</a> from xmlwriter.h</li><li> line 1060: Function <a href="../html/libxml-xmlwriter.html#xmlTextWriterStartElement">xmlTextWriterStartElement</a> from xmlwriter.h</li><li> line 1067: Function <a href="../html/libxml-xmlwriter.html#xmlTextWriterWriteElement">xmlTextWriterWriteElement</a> from xmlwriter.h</li><li> line 1075: Function <a href="../html/libxml-xmlwriter.html#xmlTextWriterEndElement">xmlTextWriterEndElement</a> from xmlwriter.h</li><li> line 1085: Function <a href="../html/libxml-xmlwriter.html#xmlTextWriterEndDocument">xmlTextWriterEndDocument</a> from xmlwriter.h</li><li> line 1091: Function <a href="../html/libxml-xmlwriter.html#xmlFreeTextWriter">xmlFreeTextWriter</a> from xmlwriter.h</li><li> line 1093: Function <a href="../html/libxml-tree.html#xmlSaveFileEnc">xmlSaveFileEnc</a> from tree.h</li><li> line 1095: Function <a href="../html/libxml-tree.html#xmlFreeDoc">xmlFreeDoc</a> from tree.h</li><li> line 1115: Type <a href="../html/libxml-encoding.html#xmlCharEncodingHandlerPtr">xmlCharEncodingHandlerPtr</a> from encoding.h</li><li> line 1120: Function <a href="../html/libxml-encoding.html#xmlFindCharEncodingHandler">xmlFindCharEncodingHandler</a> from encoding.h</li></ul><p>Usage:</p><p>testWriter</p><p>Author: Alfred Mickautsch</p><p><a href="../bugs.html">Daniel Veillard</a></p></td></tr></table></td></tr></table></td></tr></table></td></tr></table></td></tr></table></body></html>
+</style><title>Libxml2 set of examples</title></head><body bgcolor="#8b7765" text="#000000" link="#000000" vlink="#000000"><table border="0" width="100%" cellpadding="5" cellspacing="0" align="center"><tr><td width="120"><a href="http://swpat.ffii.org/"><img src="../epatents.png" alt="Action against software patents" /></a></td><td width="180"><a href="http://www.gnome.org/"><img src="../gnome2.png" alt="Gnome2 Logo" /></a><a href="http://www.w3.org/Status"><img src="../w3c.png" alt="W3C Logo" /></a><a href="http://www.redhat.com/"><img src="../redhat.gif" alt="Red Hat Logo" /></a><div align="left"><a href="http://xmlsoft.org/"><img src="../Libxml2-Logo-180x168.gif" alt="Made with Libxml2 Logo" /></a></div></td><td><table border="0" width="90%" cellpadding="2" cellspacing="0" align="center" bgcolor="#000000"><tr><td><table width="100%" border="0" cellspacing="1" cellpadding="3" bgcolor="#fffacd"><tr><td align="center"><h1></h1><h2>Libxml2 set of examples</h2></td></tr></table></td></tr></table></td></tr></table><table border="0" cellpadding="4" cellspacing="0" width="100%" align="center"><tr><td bgcolor="#8b7765"><table border="0" cellspacing="0" cellpadding="2" width="100%"><tr><td valign="top" width="200" bgcolor="#8b7765"><table border="0" cellspacing="0" cellpadding="1" width="100%" bgcolor="#000000"><tr><td><table width="100%" border="0" cellspacing="1" cellpadding="3"><tr><td colspan="1" bgcolor="#eecfa1" align="center"><center><b>Examples Menu</b></center></td></tr><tr><td bgcolor="#fffacd"><form action="../search.php" enctype="application/x-www-form-urlencoded" method="get"><input name="query" type="text" size="20" value="" /><input name="submit" type="submit" value="Search ..." /></form><ul><li><a href="../index.html">Home</a></li><li><a style="font-weight:bold" href="../docs.html">Developer Menu</a></li><li><a style="font-weight:bold" href="../html/index.html">API Menu</a></li><li><a href="#InputOutput">InputOutput Examples</a></li><li><a href="#Parsing">Parsing Examples</a></li><li><a href="#Tree">Tree Examples</a></li><li><a href="#XPath">XPath Examples</a></li><li><a href="#xmlReader">xmlReader Examples</a></li><li><a href="#xmlWriter">xmlWriter Examples</a></li><li><a href="../guidelines.html">XML Guidelines</a></li></ul></td></tr></table><table width="100%" border="0" cellspacing="1" cellpadding="3"><tr><td colspan="1" bgcolor="#eecfa1" align="center"><center><b>Related links</b></center></td></tr><tr><td bgcolor="#fffacd"><ul><li><a href="http://mail.gnome.org/archives/xml/">Mail archive</a></li><li><a href="http://xmlsoft.org/XSLT/">XSLT libxslt</a></li><li><a href="http://phd.cs.unibo.it/gdome2/">DOM gdome2</a></li><li><a href="http://www.aleksey.com/xmlsec/">XML-DSig xmlsec</a></li><li><a href="ftp://xmlsoft.org/">FTP</a></li><li><a href="http://www.zlatkovic.com/projects/libxml/">Windows binaries</a></li><li><a href="http://garypennington.net/libxml2/">Solaris binaries</a></li><li><a href="http://www.zveno.com/open_source/libxml2xslt.html">MacOsX binaries</a></li><li><a href="http://sourceforge.net/projects/libxml2-pas/">Pascal bindings</a></li><li><a href="http://bugzilla.gnome.org/buglist.cgi?product=libxml2">Bug Tracker</a></li></ul></td></tr></table></td></tr></table></td><td valign="top" bgcolor="#8b7765"><table border="0" cellspacing="0" cellpadding="1" width="100%"><tr><td><table border="0" cellspacing="0" cellpadding="1" width="100%" bgcolor="#000000"><tr><td><table border="0" cellpadding="3" cellspacing="1" width="100%"><tr><td bgcolor="#fffacd"><p> The examples are stored per section depending on the main focus
+    of the example:</p><ul><li><p><a href="#InputOutput">InputOutput</a> :</p><ul><li><a href="#io1.c">io1.c</a>: Example of custom Input/Output</li></ul></li><li><p><a href="#XPath">XPath</a> :</p><ul><li><a href="#xpath1.c">xpath1.c</a>: Evaluate XPath expression and prints result node set.</li></ul></li><li><p><a href="#xmlWriter">xmlWriter</a> :</p><ul><li><a href="#testWriter.c">testWriter.c</a>: use various APIs for the xmlWriter</li></ul></li><li><p><a href="#Parsing">Parsing</a> :</p><ul><li><a href="#parse1.c">parse1.c</a>: Parse an XML file to a tree and free it</li><li><a href="#parse2.c">parse2.c</a>: Parse and validate an XML file to a tree and free the result</li></ul></li><li><p><a href="#Tree">Tree</a> :</p><ul><li><a href="#tree1.c">tree1.c</a>: Navigates a tree to print element names</li><li><a href="#tree2.c">tree2.c</a>: Creates a tree</li></ul></li><li><p><a href="#xmlReader">xmlReader</a> :</p><ul><li><a href="#reader1.c">reader1.c</a>: Parse an XML file with an xmlReader</li><li><a href="#reader2.c">reader2.c</a>: Parse and validate an XML file with an xmlReader</li><li><a href="#reader3.c">reader3.c</a>: Show how to extract subdocuments with xmlReader</li></ul></li></ul><h2><a name="InputOutput" id="InputOutput"></a>InputOutput Examples</h2><h3><a name="io1.c" href="io1.c" id="io1.c">io1.c</a>: Example of custom Input/Output</h3><p>Demonstrate the use of xmlRegisterInputCallbacks to build a custom I/O layer, this is used in an XInclude method context to show how dynamic document can be built in a clean way.</p><p>Includes:</p><ul><li><a href="../html/libxml-parser.html">&lt;libxml/parser.h&gt;</a></li><li><a href="../html/libxml-xinclude.html">&lt;libxml/xinclude.h&gt;</a></li><li><a href="../html/libxml-tree.html">&lt;libxml/tree.h&gt;</a></li><li><a href="../html/libxml-xmlIO.html">&lt;libxml/xmlIO.h&gt;</a></li></ul><p>Uses:</p><ul><li> line 104: Type <a href="../html/libxml-tree.html#xmlDocPtr">xmlDocPtr</a> from tree.h</li><li> line 116: Function <a href="../html/libxml-xmlIO.html#xmlRegisterInputCallbacks">xmlRegisterInputCallbacks</a> from xmlIO.h</li><li> line 123: Function <a href="../html/libxml-parser.html#xmlReadMemory">xmlReadMemory</a> from parser.h</li><li> line 132: Function <a href="../html/libxml-xinclude.html#xmlXIncludeProcess">xmlXIncludeProcess</a> from xinclude.h</li><li> line 139: Function <a href="../html/libxml-tree.html#xmlDocDump">xmlDocDump</a> from tree.h</li></ul><p>Usage:</p><p>io1</p><p>Author: Daniel Veillard</p><h2><a name="Parsing" id="Parsing"></a>Parsing Examples</h2><h3><a name="parse1.c" href="parse1.c" id="parse1.c">parse1.c</a>: Parse an XML file to a tree and free it</h3><p>Demonstrate the use of xmlReadFile() to read an XML file into a tree and and xmlFreeDoc() to free the resulting tree</p><p>Includes:</p><ul><li><a href="../html/libxml-tree.html">&lt;libxml/tree.h&gt;</a></li><li><a href="../html/libxml-parser.html">&lt;libxml/parser.h&gt;</a></li></ul><p>Uses:</p><ul><li> line 24: Type <a href="../html/libxml-tree.html#xmlDocPtr">xmlDocPtr</a> from tree.h</li><li> line 26: Function <a href="../html/libxml-parser.html#xmlReadFile">xmlReadFile</a> from parser.h</li><li> line 31: Function <a href="../html/libxml-tree.html#xmlFreeDoc">xmlFreeDoc</a> from tree.h</li><li> line 45: Macro <a href="../html/libxml-xmlversion.html#LIBXML_TEST_VERSION">LIBXML_TEST_VERSION</a> from xmlversion.h</li><li> line 50: Function <a href="../html/libxml-parser.html#xmlCleanupParser">xmlCleanupParser</a> from parser.h</li><li> line 54: Function <a href="../html/libxml-xmlmemory.html#xmlMemoryDump">xmlMemoryDump</a> from xmlmemory.h</li></ul><p>Usage:</p><p>parse1 test1.xml</p><p>Author: Daniel Veillard</p><h3><a name="parse2.c" href="parse2.c" id="parse2.c">parse2.c</a>: Parse and validate an XML file to a tree and free the result</h3><p>Create a parser context for an XML file, then parse and validate the file, creating a tree, check the validation result and xmlFreeDoc() to free the resulting tree.</p><p>Includes:</p><ul><li><a href="../html/libxml-tree.html">&lt;libxml/tree.h&gt;</a></li><li><a href="../html/libxml-parser.html">&lt;libxml/parser.h&gt;</a></li></ul><p>Uses:</p><ul><li> line 25: Type <a href="../html/libxml-tree.html#xmlParserCtxtPtr">xmlParserCtxtPtr</a> from tree.h</li><li> line 26: Type <a href="../html/libxml-tree.html#xmlDocPtr">xmlDocPtr</a> from tree.h</li><li> line 29: Function <a href="../html/libxml-parser.html#xmlNewParserCtxt">xmlNewParserCtxt</a> from parser.h</li><li> line 35: Function <a href="../html/libxml-parser.html#xmlCtxtReadFile">xmlCtxtReadFile</a> from parser.h</li><li> line 44: Function <a href="../html/libxml-tree.html#xmlFreeDoc">xmlFreeDoc</a> from tree.h</li><li> line 47: Function <a href="../html/libxml-parser.html#xmlFreeParserCtxt">xmlFreeParserCtxt</a> from parser.h</li><li> line 61: Macro <a href="../html/libxml-xmlversion.html#LIBXML_TEST_VERSION">LIBXML_TEST_VERSION</a> from xmlversion.h</li><li> line 66: Function <a href="../html/libxml-parser.html#xmlCleanupParser">xmlCleanupParser</a> from parser.h</li><li> line 70: Function <a href="../html/libxml-xmlmemory.html#xmlMemoryDump">xmlMemoryDump</a> from xmlmemory.h</li></ul><p>Usage:</p><p>parse2 test2.xml</p><p>Author: Daniel Veillard</p><h2><a name="Tree" id="Tree"></a>Tree Examples</h2><h3><a name="tree1.c" href="tree1.c" id="tree1.c">tree1.c</a>: Navigates a tree to print element names</h3><p>Parse a file to a tree, use xmlDocGetRootElement() to get the root element, then walk the document and print all the element name in document order.</p><p>Includes:</p><ul><li><a href="../html/libxml-tree.html">&lt;libxml/tree.h&gt;</a></li><li><a href="../html/libxml-parser.html">&lt;libxml/parser.h&gt;</a></li></ul><p>Uses:</p><ul><li> line 65: Macro <a href="../html/libxml-xmlversion.html#LIBXML_TEST_VERSION">LIBXML_TEST_VERSION</a> from xmlversion.h</li><li> line 65: Function <a href="../html/libxml-parser.html#xmlParseFile">xmlParseFile</a> from parser.h</li><li> line 72: Function <a href="../html/libxml-tree.html#xmlDocGetRootElement">xmlDocGetRootElement</a> from tree.h</li><li> line 77: Function <a href="../html/libxml-tree.html#xmlFreeDoc">xmlFreeDoc</a> from tree.h</li><li> line 83: Function <a href="../html/libxml-parser.html#xmlCleanupParser">xmlCleanupParser</a> from parser.h</li></ul><p>Usage:</p><p>tree1 filename_or_URL</p><p>Author: Dodji Seketeli</p><h3><a name="tree2.c" href="tree2.c" id="tree2.c">tree2.c</a>: Creates a tree</h3><p>Shows how to create document, nodes and dump it to stdout or file.</p><p>Includes:</p><ul><li><a href="../html/libxml-tree.html">&lt;libxml/tree.h&gt;</a></li><li><a href="../html/libxml-parser.html">&lt;libxml/parser.h&gt;</a></li></ul><p>Uses:</p><ul><li> line 32: Macro <a href="../html/libxml-xmlversion.html#LIBXML_TEST_VERSION">LIBXML_TEST_VERSION</a> from xmlversion.h</li><li> line 37: Function <a href="../html/libxml-tree.html#xmlNewDoc">xmlNewDoc</a> from tree.h</li><li> line 39: Function <a href="../html/libxml-tree.html#xmlDocSetRootElement">xmlDocSetRootElement</a> from tree.h</li><li> line 44: Function <a href="../html/libxml-tree.html#xmlCreateIntSubset">xmlCreateIntSubset</a> from tree.h</li><li> line 72: Function <a href="../html/libxml-tree.html#xmlNewNode">xmlNewNode</a> from tree.h</li><li> line 73: Function <a href="../html/libxml-tree.html#xmlNewText">xmlNewText</a> from tree.h</li><li> line 76: Function <a href="../html/libxml-tree.html#xmlAddChild">xmlAddChild</a> from tree.h</li><li> line 86: Function <a href="../html/libxml-tree.html#xmlNewChild">xmlNewChild</a> from tree.h</li><li> line 87: Function <a href="../html/libxml-tree.html#xmlNewProp">xmlNewProp</a> from tree.h</li><li> line 94: Function <a href="../html/libxml-tree.html#xmlSaveFormatFileEnc">xmlSaveFormatFileEnc</a> from tree.h</li><li> line 97: Function <a href="../html/libxml-tree.html#xmlFreeDoc">xmlFreeDoc</a> from tree.h</li><li> line 103: Function <a href="../html/libxml-parser.html#xmlCleanupParser">xmlCleanupParser</a> from parser.h</li><li> line 108: Function <a href="../html/libxml-xmlmemory.html#xmlMemoryDump">xmlMemoryDump</a> from xmlmemory.h</li></ul><p>Usage:</p><p>tree2 &lt;filename&gt;  -Default output: stdout</p><p>Author: Lucas Brasilino &lt;brasilino@recife.pe.gov.br&gt;</p><h2><a name="XPath" id="XPath"></a>XPath Examples</h2><h3><a name="xpath1.c" href="xpath1.c" id="xpath1.c">xpath1.c</a>: Evaluate XPath expression and prints result node set.</h3><p>Shows how to evaluate XPath expression and register known namespaces in XPath context.</p><p>Includes:</p><ul><li><a href="../html/libxml-xpath.html">&lt;libxml/xpath.h&gt;</a></li><li><a href="../html/libxml-parser.html">&lt;libxml/parser.h&gt;</a></li><li><a href="../html/libxml-xpathInternals.html">&lt;libxml/xpathInternals.h&gt;</a></li><li><a href="../html/libxml-tree.html">&lt;libxml/tree.h&gt;</a></li></ul><p>Uses:</p><ul><li> line 35: Function <a href="../html/libxml-parser.html#xmlInitParser">xmlInitParser</a> from parser.h</li><li> line 39: Macro <a href="../html/libxml-xmlversion.html#LIBXML_TEST_VERSION">LIBXML_TEST_VERSION</a> from xmlversion.h</li><li> line 45: Function <a href="../html/libxml-parser.html#xmlCleanupParser">xmlCleanupParser</a> from parser.h</li><li> line 50: Function <a href="../html/libxml-xmlmemory.html#xmlMemoryDump">xmlMemoryDump</a> from xmlmemory.h</li><li> line 82: Type <a href="../html/libxml-tree.html#xmlDocPtr">xmlDocPtr</a> from tree.h</li><li> line 83: Type <a href="../html/libxml-xpath.html#xmlXPathContextPtr">xmlXPathContextPtr</a> from xpath.h</li><li> line 84: Type <a href="../html/libxml-xpath.html#xmlXPathObjectPtr">xmlXPathObjectPtr</a> from xpath.h</li><li> line 90: Function <a href="../html/libxml-parser.html#xmlParseFile">xmlParseFile</a> from parser.h</li><li> line 97: Function <a href="../html/libxml-xpath.html#xmlXPathNewContext">xmlXPathNewContext</a> from xpath.h</li><li> line 113: Function <a href="../html/libxml-xpath.html#xmlXPathEvalExpression">xmlXPathEvalExpression</a> from xpath.h</li><li> line 125: Function <a href="../html/libxml-xpath.html#xmlXPathFreeObject">xmlXPathFreeObject</a> from xpath.h</li><li> line 126: Function <a href="../html/libxml-xpath.html#xmlXPathFreeContext">xmlXPathFreeContext</a> from xpath.h</li><li> line 127: Function <a href="../html/libxml-tree.html#xmlFreeDoc">xmlFreeDoc</a> from tree.h</li><li> line 152: Function <a href="../html/libxml-xmlstring.html#xmlStrdup">xmlStrdup</a> from xmlstring.h</li><li> line 176: Function <a href="../html/libxml-xmlstring.html#xmlStrchr">xmlStrchr</a> from xmlstring.h</li><li> line 182: Function <a href="../html/libxml-xpathInternals.html#xmlXPathRegisterNs">xmlXPathRegisterNs</a> from xpathInternals.h</li><li> line 202: Type <a href="../html/libxml-tree.html#xmlNodePtr">xmlNodePtr</a> from tree.h</li><li> line 214: Type <a href="../html/libxml-tree.html#xmlNsPtr">xmlNsPtr</a> from tree.h</li></ul><p>Usage:</p><p>xpath1 &lt;xml-file&gt; &lt;xpath-expr&gt; [&lt;known-ns-list&gt;]</p><p>Author: Aleksey Sanin</p><h2><a name="xmlReader" id="xmlReader"></a>xmlReader Examples</h2><h3><a name="reader1.c" href="reader1.c" id="reader1.c">reader1.c</a>: Parse an XML file with an xmlReader</h3><p>Demonstrate the use of xmlReaderForFile() to parse an XML file and dump the informations about the nodes found in the process</p><p>Includes:</p><ul><li><a href="../html/libxml-xmlreader.html">&lt;libxml/xmlreader.h&gt;</a></li></ul><p>Uses:</p><ul><li> line 25: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderConstName">xmlTextReaderConstName</a> from xmlreader.h</li><li> line 29: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderConstValue">xmlTextReaderConstValue</a> from xmlreader.h</li><li> line 32: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderDepth">xmlTextReaderDepth</a> from xmlreader.h</li><li> line 33: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderNodeType">xmlTextReaderNodeType</a> from xmlreader.h</li><li> line 35: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderIsEmptyElement">xmlTextReaderIsEmptyElement</a> from xmlreader.h</li><li> line 36: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderHasValue">xmlTextReaderHasValue</a> from xmlreader.h</li><li> line 40: Function <a href="../html/libxml-xmlstring.html#xmlStrlen">xmlStrlen</a> from xmlstring.h</li><li> line 55: Type <a href="../html/libxml-xmlreader.html#xmlTextReaderPtr">xmlTextReaderPtr</a> from xmlreader.h</li><li> line 58: Function <a href="../html/libxml-xmlreader.html#xmlReaderForFile">xmlReaderForFile</a> from xmlreader.h</li><li> line 63: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderRead">xmlTextReaderRead</a> from xmlreader.h</li><li> line 65: Function <a href="../html/libxml-xmlreader.html#xmlFreeTextReader">xmlFreeTextReader</a> from xmlreader.h</li><li> line 94: Function <a href="../html/libxml-xmlmemory.html#xmlMemoryDump">xmlMemoryDump</a> from xmlmemory.h</li></ul><p>Usage:</p><p>reader1 &lt;filename&gt;</p><p>Author: Daniel Veillard</p><h3><a name="reader2.c" href="reader2.c" id="reader2.c">reader2.c</a>: Parse and validate an XML file with an xmlReader</h3><p>Demonstrate the use of xmlReaderForFile() to parse an XML file validating the content in the process and activating options like entities substitution, and DTD attributes defaulting</p><p>Includes:</p><ul><li><a href="../html/libxml-xmlreader.html">&lt;libxml/xmlreader.h&gt;</a></li></ul><p>Uses:</p><ul><li> line 26: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderConstName">xmlTextReaderConstName</a> from xmlreader.h</li><li> line 30: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderConstValue">xmlTextReaderConstValue</a> from xmlreader.h</li><li> line 33: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderDepth">xmlTextReaderDepth</a> from xmlreader.h</li><li> line 34: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderNodeType">xmlTextReaderNodeType</a> from xmlreader.h</li><li> line 36: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderIsEmptyElement">xmlTextReaderIsEmptyElement</a> from xmlreader.h</li><li> line 37: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderHasValue">xmlTextReaderHasValue</a> from xmlreader.h</li><li> line 41: Function <a href="../html/libxml-xmlstring.html#xmlStrlen">xmlStrlen</a> from xmlstring.h</li><li> line 56: Type <a href="../html/libxml-xmlreader.html#xmlTextReaderPtr">xmlTextReaderPtr</a> from xmlreader.h</li><li> line 64: Function <a href="../html/libxml-xmlreader.html#xmlReaderForFile">xmlReaderForFile</a> from xmlreader.h</li><li> line 72: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderRead">xmlTextReaderRead</a> from xmlreader.h</li><li> line 77: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderIsValid">xmlTextReaderIsValid</a> from xmlreader.h</li><li> line 80: Function <a href="../html/libxml-xmlreader.html#xmlFreeTextReader">xmlFreeTextReader</a> from xmlreader.h</li></ul><p>Usage:</p><p>reader2 &lt;valid_xml_filename&gt;</p><p>Author: Daniel Veillard</p><h3><a name="reader3.c" href="reader3.c" id="reader3.c">reader3.c</a>: Show how to extract subdocuments with xmlReader</h3><p>Demonstrate the use of xmlTextReaderPreservePattern() to parse an XML file with the xmlReader while collecting only some subparts of the document</p><p>Includes:</p><ul><li><a href="../html/libxml-xmlreader.html">&lt;libxml/xmlreader.h&gt;</a></li></ul><p>Uses:</p><ul><li> line 27: Type <a href="../html/libxml-xmlreader.html#xmlTextReaderPtr">xmlTextReaderPtr</a> from xmlreader.h</li><li> line 33: Function <a href="../html/libxml-xmlreader.html#xmlReaderForFile">xmlReaderForFile</a> from xmlreader.h</li><li> line 38: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderPreservePattern">xmlTextReaderPreservePattern</a> from xmlreader.h</li><li> line 47: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderRead">xmlTextReaderRead</a> from xmlreader.h</li><li> line 57: Function <a href="../html/libxml-xmlreader.html#xmlTextReaderCurrentDoc">xmlTextReaderCurrentDoc</a> from xmlreader.h</li><li> line 61: Function <a href="../html/libxml-xmlreader.html#xmlFreeTextReader">xmlFreeTextReader</a> from xmlreader.h</li><li> line 72: Type <a href="../html/libxml-tree.html#xmlDocPtr">xmlDocPtr</a> from tree.h</li><li> line 91: Function <a href="../html/libxml-tree.html#xmlDocDump">xmlDocDump</a> from tree.h</li></ul><p>Usage:</p><p>reader3</p><p>Author: Daniel Veillard</p><h2><a name="xmlWriter" id="xmlWriter"></a>xmlWriter Examples</h2><h3><a name="testWriter.c" href="testWriter.c" id="testWriter.c">testWriter.c</a>: use various APIs for the xmlWriter</h3><p>tests a number of APIs for the xmlWriter, especially the various methods to write to a filename, to a memory buffer, to a new document, or to a subtree. It shows how to do encoding string conversions too. The resulting documents are then serialized.</p><p>Includes:</p><ul><li><a href="../html/libxml-encoding.html">&lt;libxml/encoding.h&gt;</a></li><li><a href="../html/libxml-xmlwriter.html">&lt;libxml/xmlwriter.h&gt;</a></li></ul><p>Uses:</p><ul><li> line 38: Macro <a href="../html/libxml-xmlversion.html#LIBXML_TEST_VERSION">LIBXML_TEST_VERSION</a> from xmlversion.h</li><li> line 52: Function <a href="../html/libxml-parser.html#xmlCleanupParser">xmlCleanupParser</a> from parser.h</li><li> line 56: Function <a href="../html/libxml-xmlmemory.html#xmlMemoryDump">xmlMemoryDump</a> from xmlmemory.h</li><li> line 73: Function <a href="../html/libxml-xmlwriter.html#xmlNewTextWriterFilename">xmlNewTextWriterFilename</a> from xmlwriter.h</li><li> line 335: Type <a href="../html/libxml-tree.html#xmlBufferPtr">xmlBufferPtr</a> from tree.h</li><li> line 340: Function <a href="../html/libxml-tree.html#xmlBufferCreate">xmlBufferCreate</a> from tree.h</li><li> line 348: Function <a href="../html/libxml-xmlwriter.html#xmlNewTextWriterMemory">xmlNewTextWriterMemory</a> from xmlwriter.h</li><li> line 618: Function <a href="../html/libxml-xmlwriter.html#xmlNewTextWriterDoc">xmlNewTextWriterDoc</a> from xmlwriter.h</li><li> line 861: Type <a href="../html/libxml-xmlwriter.html#xmlTextWriterPtr">xmlTextWriterPtr</a> from xmlwriter.h</li><li> line 862: Type <a href="../html/libxml-tree.html#xmlDocPtr">xmlDocPtr</a> from tree.h</li><li> line 863: Type <a href="../html/libxml-tree.html#xmlNodePtr">xmlNodePtr</a> from tree.h</li><li> line 867: Macro <a href="../html/libxml-parser.html#XML_DEFAULT_VERSION">XML_DEFAULT_VERSION</a> from parser.h</li><li> line 867: Function <a href="../html/libxml-tree.html#xmlNewDoc">xmlNewDoc</a> from tree.h</li><li> line 876: Function <a href="../html/libxml-tree.html#xmlNewDocNode">xmlNewDocNode</a> from tree.h</li><li> line 883: Function <a href="../html/libxml-tree.html#xmlDocSetRootElement">xmlDocSetRootElement</a> from tree.h</li><li> line 886: Function <a href="../html/libxml-xmlwriter.html#xmlNewTextWriterTree">xmlNewTextWriterTree</a> from xmlwriter.h</li><li> line 895: Function <a href="../html/libxml-xmlwriter.html#xmlTextWriterStartDocument">xmlTextWriterStartDocument</a> from xmlwriter.h</li><li> line 905: Function <a href="../html/libxml-xmlwriter.html#xmlTextWriterWriteComment">xmlTextWriterWriteComment</a> from xmlwriter.h</li><li> line 931: Function <a href="../html/libxml-xmlwriter.html#xmlTextWriterWriteAttribute">xmlTextWriterWriteAttribute</a> from xmlwriter.h</li><li> line 940: Function <a href="../html/libxml-xmlwriter.html#xmlTextWriterWriteFormatComment">xmlTextWriterWriteFormatComment</a> from xmlwriter.h</li><li> line 1052: Function <a href="../html/libxml-xmlwriter.html#xmlTextWriterWriteFormatElement">xmlTextWriterWriteFormatElement</a> from xmlwriter.h</li><li> line 1075: Function <a href="../html/libxml-xmlwriter.html#xmlTextWriterStartElement">xmlTextWriterStartElement</a> from xmlwriter.h</li><li> line 1082: Function <a href="../html/libxml-xmlwriter.html#xmlTextWriterWriteElement">xmlTextWriterWriteElement</a> from xmlwriter.h</li><li> line 1090: Function <a href="../html/libxml-xmlwriter.html#xmlTextWriterEndElement">xmlTextWriterEndElement</a> from xmlwriter.h</li><li> line 1100: Function <a href="../html/libxml-xmlwriter.html#xmlTextWriterEndDocument">xmlTextWriterEndDocument</a> from xmlwriter.h</li><li> line 1106: Function <a href="../html/libxml-xmlwriter.html#xmlFreeTextWriter">xmlFreeTextWriter</a> from xmlwriter.h</li><li> line 1108: Function <a href="../html/libxml-tree.html#xmlSaveFileEnc">xmlSaveFileEnc</a> from tree.h</li><li> line 1110: Function <a href="../html/libxml-tree.html#xmlFreeDoc">xmlFreeDoc</a> from tree.h</li><li> line 1130: Type <a href="../html/libxml-encoding.html#xmlCharEncodingHandlerPtr">xmlCharEncodingHandlerPtr</a> from encoding.h</li><li> line 1135: Function <a href="../html/libxml-encoding.html#xmlFindCharEncodingHandler">xmlFindCharEncodingHandler</a> from encoding.h</li></ul><p>Usage:</p><p>testWriter</p><p>Author: Alfred Mickautsch</p><p><a href="../bugs.html">Daniel Veillard</a></p></td></tr></table></td></tr></table></td></tr></table></td></tr></table></td></tr></table></body></html>
diff --git a/doc/examples/index.py b/doc/examples/index.py
index 1ae3a88..14ec306 100755
--- a/doc/examples/index.py
+++ b/doc/examples/index.py
@@ -252,8 +252,10 @@
         Makefile = Makefile + "%s_SOURCES=%s.c\n%s_LDFLAGS=\n%s_DEPENDENCIES= $(DEPS)\n%s_LDADD= @RDL_LIBS@ $(LDADDS)\n\n" % (example, example, example,
 	       example, example)
     Makefile = Makefile + "tests: $(noinst_PROGRAMS)\n"
+    Makefile = Makefile + "\t@(echo > .memdump)\n"
     for test in tests:
         Makefile = Makefile + "\t@(%s)\n" % (test)
+        Makefile = Makefile + '\t@(grep "MORY ALLO" .memdump  | grep -v "MEMORY ALLOCATED : 0" ; exit 0)\n'
     Makefile = Makefile + "\n\n"
     try:
 	old = open("Makefile.am", "r").read()
diff --git a/doc/examples/io1.c b/doc/examples/io1.c
new file mode 100644
index 0000000..b505f80
--- /dev/null
+++ b/doc/examples/io1.c
@@ -0,0 +1,154 @@
+/**
+ * section: InputOutput
+ * synopsis: Example of custom Input/Output
+ * purpose: Demonstrate the use of xmlRegisterInputCallbacks
+ *          to build a custom I/O layer, this is used in an
+ *          XInclude method context to show how dynamic document can
+ *          be built in a clean way.
+ * usage: io1
+ * test: io1 > io1.tmp ; diff io1.tmp io1.res ; rm -f io1.tmp
+ * author: Daniel Veillard
+ * copy: see Copyright for the status of this software.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+#include <libxml/xinclude.h>
+#include <libxml/xmlIO.h>
+
+static const char *result = "<list><people>a</people><people>b</people></list>";
+static const char *cur = NULL;
+static int rlen;
+
+/**
+ * sqlMatch:
+ * @URI: an URI to test
+ *
+ * Check for an sql: query
+ *
+ * Returns 1 if yes and 0 if another Input module should be used
+ */
+static int
+sqlMatch(const char * URI) {
+    if ((URI != NULL) && (!strncmp(URI, "sql:", 4)))
+        return(1);
+    return(0);
+}
+
+/**
+ * sqlOpen:
+ * @URI: an URI to test
+ *
+ * Return a pointer to the sql: query handler, in this example simply
+ * the current pointer...
+ *
+ * Returns an Input context or NULL in case or error
+ */
+static void *
+sqlOpen(const char * URI) {
+    if ((URI == NULL) || (strncmp(URI, "sql:", 4)))
+        return(NULL);
+    cur = result;
+    rlen = strlen(result);
+    return((void *) cur);
+}
+
+/**
+ * sqlClose:
+ * @context: the read context
+ *
+ * Close the sql: query handler
+ *
+ * Returns 0 or -1 in case of error
+ */
+static int
+sqlClose(void * context) {
+    if (context == NULL) return(-1);
+    cur = NULL;
+    rlen = 0;
+    return(0);
+}
+
+/**
+ * sqlRead:
+ * @context: the read context
+ * @buffer: where to store data
+ * @len: number of bytes to read
+ *
+ * Implement an sql: query read.
+ *
+ * Returns the number of bytes read or -1 in case of error
+ */
+static int
+sqlRead(void * context, char * buffer, int len) {
+   const char *ptr = (const char *) context;
+
+   if ((context == NULL) || (buffer == NULL) || (len < 0))
+       return(-1);
+
+   if (len > rlen) len = rlen;
+   memcpy(buffer, ptr, len);
+   rlen -= len;
+   return(len);
+}
+
+const char *include = "<?xml version='1.0'?>\n\
+<document xmlns:xi=\"http://www.w3.org/2003/XInclude\">\n\
+  <p>List of people:</p>\n\
+  <xi:include href=\"sql:select_name_from_people\"/>\n\
+</document>\n";
+
+int main(void) {
+    xmlDocPtr doc;
+
+    /*
+     * this initialize the library and check potential ABI mismatches
+     * between the version it was compiled for and the actual shared
+     * library used.
+     */
+    LIBXML_TEST_VERSION
+
+    /*
+     * register the new I/O handlers
+     */
+    if (xmlRegisterInputCallbacks(sqlMatch, sqlOpen, sqlRead, sqlClose) < 0) {
+        fprintf(stderr, "failed to register SQL handler\n");
+	exit(1);
+    }
+    /*
+     * parse include into a document
+     */
+    doc = xmlReadMemory(include, strlen(include), "include.xml", NULL, 0);
+    if (doc == NULL) {
+        fprintf(stderr, "failed to parse the including file\n");
+	exit(1);
+    }
+    /*
+     * apply the XInclude process, this should trigger the I/O just
+     * registered.
+     */
+    if (xmlXIncludeProcess(doc) <= 0) {
+        fprintf(stderr, "XInclude processing failed\n");
+	exit(1);
+    }
+    /*
+     * save the output for checking to stdout
+     */
+    xmlDocDump(stdout, doc);
+    /*
+     * Free the document
+     */
+    xmlFreeDoc(doc);
+
+    /*
+     * Cleanup function for the XML library.
+     */
+    xmlCleanupParser();
+    /*
+     * this is to debug memory for regression tests
+     */
+    xmlMemoryDump();
+    return(0);
+}
diff --git a/doc/examples/io1.res b/doc/examples/io1.res
new file mode 100644
index 0000000..4a4c036
--- /dev/null
+++ b/doc/examples/io1.res
@@ -0,0 +1,5 @@
+<?xml version="1.0"?>
+<document xmlns:xi="http://www.w3.org/2003/XInclude">
+  <p>List of people:</p>
+  <list><people>a</people><people>b</people></list>
+</document>
diff --git a/doc/examples/parse1.c b/doc/examples/parse1.c
index a21896f..b44b03b 100644
--- a/doc/examples/parse1.c
+++ b/doc/examples/parse1.c
@@ -48,5 +48,9 @@
      * Cleanup function for the XML library.
      */
     xmlCleanupParser();
+    /*
+     * this is to debug memory for regression tests
+     */
+    xmlMemoryDump();
     return(0);
 }
diff --git a/doc/examples/parse2.c b/doc/examples/parse2.c
index aaedd4a..aed7676 100644
--- a/doc/examples/parse2.c
+++ b/doc/examples/parse2.c
@@ -64,5 +64,9 @@
      * Cleanup function for the XML library.
      */
     xmlCleanupParser();
+    /*
+     * this is to debug memory for regression tests
+     */
+    xmlMemoryDump();
     return(0);
 }
diff --git a/doc/examples/reader1.c b/doc/examples/reader1.c
index 385f1d3..c030e0f 100644
--- a/doc/examples/reader1.c
+++ b/doc/examples/reader1.c
@@ -88,5 +88,9 @@
      * Cleanup function for the XML library.
      */
     xmlCleanupParser();
+    /*
+     * this is to debug memory for regression tests
+     */
+    xmlMemoryDump();
     return(0);
 }
diff --git a/doc/examples/reader2.c b/doc/examples/reader2.c
index 784746a..65c274d 100644
--- a/doc/examples/reader2.c
+++ b/doc/examples/reader2.c
@@ -103,5 +103,9 @@
      * Cleanup function for the XML library.
      */
     xmlCleanupParser();
+    /*
+     * this is to debug memory for regression tests
+     */
+    xmlMemoryDump();
     return(0);
 }
diff --git a/doc/examples/reader3.c b/doc/examples/reader3.c
index b68adaa..2ccb6ad 100644
--- a/doc/examples/reader3.c
+++ b/doc/examples/reader3.c
@@ -100,5 +100,9 @@
      * Cleanup function for the XML library.
      */
     xmlCleanupParser();
+    /*
+     * this is to debug memory for regression tests
+     */
+    xmlMemoryDump();
     return(0);
 }
diff --git a/doc/examples/testWriter.c b/doc/examples/testWriter.c
index c5eaf83..c6bb41a 100644
--- a/doc/examples/testWriter.c
+++ b/doc/examples/testWriter.c
@@ -27,6 +27,13 @@
 int
 main(void)
 {
+    /*
+     * this initialize the library and check potential ABI mismatches
+     * between the version it was compiled for and the actual shared
+     * library used.
+     */
+    LIBXML_TEST_VERSION
+
     /* first, the file version */
     testXmlwriterFilename("writer1.res");
 
@@ -39,6 +46,14 @@
     /* next, the tree version */
     testXmlwriterTree("writer4.res");
 
+    /*
+     * Cleanup function for the XML library.
+     */
+    xmlCleanupParser();
+    /*
+     * this is to debug memory for regression tests
+     */
+    xmlMemoryDump();
     return 0;
 }
 
@@ -53,6 +68,7 @@
 {
     int rc;
     xmlTextWriterPtr writer;
+    xmlChar *tmp;
 
     /* Create a new XmlWriter for uri, with no compression. */
     writer = xmlNewTextWriterFilename(uri, 0);
@@ -84,15 +100,15 @@
      * Please observe, that the input to the xmlTextWriter functions
      * HAS to be in UTF-8, even if the output XML is encoded
      * in iso-8859-1 */
-    rc = xmlTextWriterWriteComment(writer,
-                                   ConvertInput
-                                   ("This is a comment with special chars: <äöü>",
-                                    MY_ENCODING));
+    tmp = ConvertInput("This is a comment with special chars: <äöü>",
+                       MY_ENCODING);
+    rc = xmlTextWriterWriteComment(writer, tmp);
     if (rc < 0) {
         printf
             ("testXmlwriterFilename: Error at xmlTextWriterWriteComment\n");
         return;
     }
+    if (tmp != NULL) xmlFree(tmp);
 
     /* Start an element named "ORDER" as child of EXAMPLE. */
     rc = xmlTextWriterStartElement(writer, BAD_CAST "ORDER");
@@ -121,15 +137,16 @@
     }
 
     /* Write a comment as child of ORDER */
+    tmp = ConvertInput("<äöü>", MY_ENCODING);
     rc = xmlTextWriterWriteFormatComment(writer,
-                                         "This is another comment with special chars: %s",
-                                         ConvertInput("<äöü>",
-                                                      MY_ENCODING));
+		     "This is another comment with special chars: %s",
+		     tmp);
     if (rc < 0) {
         printf
             ("testXmlwriterFilename: Error at xmlTextWriterWriteFormatComment\n");
         return;
     }
+    if (tmp != NULL) xmlFree(tmp);
 
     /* Start an element named "HEADER" as child of ORDER. */
     rc = xmlTextWriterStartElement(writer, BAD_CAST "HEADER");
@@ -158,22 +175,24 @@
     }
 
     /* Write an element named "NAME_1" as child of HEADER. */
-    rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_1",
-                                   ConvertInput("Müller", MY_ENCODING));
+    tmp = ConvertInput("Müller", MY_ENCODING);
+    rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_1", tmp);
     if (rc < 0) {
         printf
             ("testXmlwriterFilename: Error at xmlTextWriterWriteElement\n");
         return;
     }
+    if (tmp != NULL) xmlFree(tmp);
 
     /* Write an element named "NAME_2" as child of HEADER. */
-    rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_2",
-                                   ConvertInput("Jörg", MY_ENCODING));
+    tmp = ConvertInput("Jörg", MY_ENCODING);
+    rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_2", tmp);
     if (rc < 0) {
         printf
             ("testXmlwriterFilename: Error at xmlTextWriterWriteElement\n");
         return;
     }
+    if (tmp != NULL) xmlFree(tmp);
 
     /* Close the element named HEADER. */
     rc = xmlTextWriterEndElement(writer);
@@ -318,6 +337,7 @@
     int rc;
     xmlTextWriterPtr writer;
     xmlBufferPtr buf;
+    xmlChar *tmp;
     FILE *fp;
 
     /* Create a new XML buffer, to which the XML document will be
@@ -359,15 +379,15 @@
      * Please observe, that the input to the xmlTextWriter functions
      * HAS to be in UTF-8, even if the output XML is encoded
      * in iso-8859-1 */
-    rc = xmlTextWriterWriteComment(writer,
-                                   ConvertInput
-                                   ("This is a comment with special chars: <äöü>",
-                                    MY_ENCODING));
+    tmp = ConvertInput("This is a comment with special chars: <äöü>",
+                       MY_ENCODING);
+    rc = xmlTextWriterWriteComment(writer, tmp);
     if (rc < 0) {
         printf
             ("testXmlwriterMemory: Error at xmlTextWriterWriteComment\n");
         return;
     }
+    if (tmp != NULL) xmlFree(tmp);
 
     /* Start an element named "ORDER" as child of EXAMPLE. */
     rc = xmlTextWriterStartElement(writer, BAD_CAST "ORDER");
@@ -396,15 +416,16 @@
     }
 
     /* Write a comment as child of ORDER */
+    tmp = ConvertInput("<äöü>", MY_ENCODING);
     rc = xmlTextWriterWriteFormatComment(writer,
-                                         "This is another comment with special chars: %s",
-                                         ConvertInput("<äöü>",
-                                                      MY_ENCODING));
+		     "This is another comment with special chars: %s",
+                                         tmp);
     if (rc < 0) {
         printf
             ("testXmlwriterMemory: Error at xmlTextWriterWriteFormatComment\n");
         return;
     }
+    if (tmp != NULL) xmlFree(tmp);
 
     /* Start an element named "HEADER" as child of ORDER. */
     rc = xmlTextWriterStartElement(writer, BAD_CAST "HEADER");
@@ -433,22 +454,25 @@
     }
 
     /* Write an element named "NAME_1" as child of HEADER. */
-    rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_1",
-                                   ConvertInput("Müller", MY_ENCODING));
+    tmp = ConvertInput("Müller", MY_ENCODING);
+    rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_1", tmp);
     if (rc < 0) {
         printf
             ("testXmlwriterMemory: Error at xmlTextWriterWriteElement\n");
         return;
     }
+    if (tmp != NULL) xmlFree(tmp);
 
     /* Write an element named "NAME_2" as child of HEADER. */
-    rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_2",
-                                   ConvertInput("Jörg", MY_ENCODING));
+    tmp = ConvertInput("Jörg", MY_ENCODING);
+    rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_2", tmp);
+                                   
     if (rc < 0) {
         printf
             ("testXmlwriterMemory: Error at xmlTextWriterWriteElement\n");
         return;
     }
+    if (tmp != NULL) xmlFree(tmp);
 
     /* Close the element named HEADER. */
     rc = xmlTextWriterEndElement(writer);
@@ -583,6 +607,8 @@
     fprintf(fp, "%s", (const char *) buf->content);
 
     fclose(fp);
+
+    xmlBufferFree(buf);
 }
 
 /**
@@ -596,6 +622,7 @@
 {
     int rc;
     xmlTextWriterPtr writer;
+    xmlChar *tmp;
     xmlDocPtr doc;
 
 
@@ -627,14 +654,14 @@
      * Please observe, that the input to the xmlTextWriter functions
      * HAS to be in UTF-8, even if the output XML is encoded
      * in iso-8859-1 */
-    rc = xmlTextWriterWriteComment(writer,
-                                   ConvertInput
-                                   ("This is a comment with special chars: <äöü>",
-                                    MY_ENCODING));
+    tmp = ConvertInput("This is a comment with special chars: <äöü>",
+                       MY_ENCODING);
+    rc = xmlTextWriterWriteComment(writer, tmp);
     if (rc < 0) {
         printf("testXmlwriterDoc: Error at xmlTextWriterWriteComment\n");
         return;
     }
+    if (tmp != NULL) xmlFree(tmp);
 
     /* Start an element named "ORDER" as child of EXAMPLE. */
     rc = xmlTextWriterStartElement(writer, BAD_CAST "ORDER");
@@ -660,15 +687,16 @@
     }
 
     /* Write a comment as child of ORDER */
+    tmp = ConvertInput("<äöü>", MY_ENCODING);
     rc = xmlTextWriterWriteFormatComment(writer,
-                                         "This is another comment with special chars: %s",
-                                         ConvertInput("<äöü>",
-                                                      MY_ENCODING));
+		 "This is another comment with special chars: %s",
+		                         tmp);
     if (rc < 0) {
         printf
             ("testXmlwriterDoc: Error at xmlTextWriterWriteFormatComment\n");
         return;
     }
+    if (tmp != NULL) xmlFree(tmp);
 
     /* Start an element named "HEADER" as child of ORDER. */
     rc = xmlTextWriterStartElement(writer, BAD_CAST "HEADER");
@@ -696,20 +724,22 @@
     }
 
     /* Write an element named "NAME_1" as child of HEADER. */
-    rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_1",
-                                   ConvertInput("Müller", MY_ENCODING));
+    tmp = ConvertInput("Müller", MY_ENCODING);
+    rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_1", tmp);
     if (rc < 0) {
         printf("testXmlwriterDoc: Error at xmlTextWriterWriteElement\n");
         return;
     }
+    if (tmp != NULL) xmlFree(tmp);
 
     /* Write an element named "NAME_2" as child of HEADER. */
-    rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_2",
-                                   ConvertInput("Jörg", MY_ENCODING));
+    tmp = ConvertInput("Jörg", MY_ENCODING);
+    rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_2", tmp);
     if (rc < 0) {
         printf("testXmlwriterDoc: Error at xmlTextWriterWriteElement\n");
         return;
     }
+    if (tmp != NULL) xmlFree(tmp);
 
     /* Close the element named HEADER. */
     rc = xmlTextWriterEndElement(writer);
@@ -846,6 +876,7 @@
     xmlTextWriterPtr writer;
     xmlDocPtr doc;
     xmlNodePtr node;
+    xmlChar *tmp;
 
     /* Create a new XML DOM tree, to which the XML document will be
      * written */
@@ -887,14 +918,14 @@
      * Please observe, that the input to the xmlTextWriter functions
      * HAS to be in UTF-8, even if the output XML is encoded
      * in iso-8859-1 */
-    rc = xmlTextWriterWriteComment(writer,
-                                   ConvertInput
-                                   ("This is a comment with special chars: <äöü>",
-                                    MY_ENCODING));
+    tmp = ConvertInput("This is a comment with special chars: <äöü>",
+                       MY_ENCODING);
+    rc = xmlTextWriterWriteComment(writer, tmp);
     if (rc < 0) {
         printf("testXmlwriterTree: Error at xmlTextWriterWriteComment\n");
         return;
     }
+    if (tmp != NULL) xmlFree(tmp);
 
     /* Start an element named "ORDER" as child of EXAMPLE. */
     rc = xmlTextWriterStartElement(writer, BAD_CAST "ORDER");
@@ -922,15 +953,16 @@
     }
 
     /* Write a comment as child of ORDER */
+    tmp = ConvertInput("<äöü>", MY_ENCODING);
     rc = xmlTextWriterWriteFormatComment(writer,
-                                         "This is another comment with special chars: %s",
-                                         ConvertInput("<äöü>",
-                                                      MY_ENCODING));
+			 "This is another comment with special chars: %s",
+					  tmp);
     if (rc < 0) {
         printf
             ("testXmlwriterTree: Error at xmlTextWriterWriteFormatComment\n");
         return;
     }
+    if (tmp != NULL) xmlFree(tmp);
 
     /* Start an element named "HEADER" as child of ORDER. */
     rc = xmlTextWriterStartElement(writer, BAD_CAST "HEADER");
@@ -958,20 +990,22 @@
     }
 
     /* Write an element named "NAME_1" as child of HEADER. */
-    rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_1",
-                                   ConvertInput("Müller", MY_ENCODING));
+    tmp = ConvertInput("Müller", MY_ENCODING);
+    rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_1", tmp);
     if (rc < 0) {
         printf("testXmlwriterTree: Error at xmlTextWriterWriteElement\n");
         return;
     }
+    if (tmp != NULL) xmlFree(tmp);
 
     /* Write an element named "NAME_2" as child of HEADER. */
-    rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_2",
-                                   ConvertInput("Jörg", MY_ENCODING));
+    tmp = ConvertInput("Jörg", MY_ENCODING);
+    rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_2", tmp);
     if (rc < 0) {
         printf("testXmlwriterTree: Error at xmlTextWriterWriteElement\n");
         return;
     }
+    if (tmp != NULL) xmlFree(tmp);
 
     /* Close the element named HEADER. */
     rc = xmlTextWriterEndElement(writer);
diff --git a/doc/examples/tree2.c b/doc/examples/tree2.c
index 124898e..196ffb4 100644
--- a/doc/examples/tree2.c
+++ b/doc/examples/tree2.c
@@ -102,5 +102,9 @@
      */
     xmlCleanupParser();
 
+    /*
+     * this is to debug memory for regression tests
+     */
+    xmlMemoryDump();
     return(0);
 }
diff --git a/doc/examples/xpath1.c b/doc/examples/xpath1.c
index f6e939b..2629c3d 100644
--- a/doc/examples/xpath1.c
+++ b/doc/examples/xpath1.c
@@ -44,6 +44,10 @@
     /* Shutdown libxml */
     xmlCleanupParser();
     
+    /*
+     * this is to debug memory for regression tests
+     */
+    xmlMemoryDump();
     return 0;
 }
 
diff --git a/doc/html/libxml-dict.html b/doc/html/libxml-dict.html
index bd25698..ec5bb37 100644
--- a/doc/html/libxml-dict.html
+++ b/doc/html/libxml-dict.html
@@ -14,6 +14,7 @@
 The content of this structure is not made public by the API.
 </pre><pre class="programlisting">Typedef <a href="libxml-dict.html#xmlDict">xmlDict</a> * <a name="xmlDictPtr" id="xmlDictPtr">xmlDictPtr</a>
 </pre><pre class="programlisting"><a href="libxml-dict.html#xmlDictPtr">xmlDictPtr</a>	<a href="#xmlDictCreate">xmlDictCreate</a>		(void)</pre>
+<pre class="programlisting"><a href="libxml-dict.html#xmlDictPtr">xmlDictPtr</a>	<a href="#xmlDictCreateSub">xmlDictCreateSub</a>	(<a href="libxml-dict.html#xmlDictPtr">xmlDictPtr</a> sub)</pre>
 <pre class="programlisting">void	<a href="#xmlDictFree">xmlDictFree</a>			(<a href="libxml-dict.html#xmlDictPtr">xmlDictPtr</a> dict)</pre>
 <pre class="programlisting">const <a href="libxml-xmlstring.html#xmlChar">xmlChar</a> *	<a href="#xmlDictLookup">xmlDictLookup</a>		(<a href="libxml-dict.html#xmlDictPtr">xmlDictPtr</a> dict, <br />					 const <a href="libxml-xmlstring.html#xmlChar">xmlChar</a> * name, <br />					 int len)</pre>
 <pre class="programlisting">int	<a href="#xmlDictOwns">xmlDictOwns</a>			(<a href="libxml-dict.html#xmlDictPtr">xmlDictPtr</a> dict, <br />					 const <a href="libxml-xmlstring.html#xmlChar">xmlChar</a> * str)</pre>
@@ -25,7 +26,9 @@
 The content of this structure is not made public by the API.
 }</pre><h3><a name="xmlDictCreate" id="xmlDictCreate"></a>Function: xmlDictCreate</h3><pre class="programlisting"><a href="libxml-dict.html#xmlDictPtr">xmlDictPtr</a>	xmlDictCreate		(void)<br />
 </pre><p>Create a new dictionary</p>
-<div class="variablelist"><table border="0"><col align="left" /><tbody><tr><td><span class="term"><i><tt>Returns</tt></i>:</span></td><td>the newly created object, or NULL if an error occured.</td></tr></tbody></table></div><h3><a name="xmlDictFree" id="xmlDictFree"></a>Function: xmlDictFree</h3><pre class="programlisting">void	xmlDictFree			(<a href="libxml-dict.html#xmlDictPtr">xmlDictPtr</a> dict)<br />
+<div class="variablelist"><table border="0"><col align="left" /><tbody><tr><td><span class="term"><i><tt>Returns</tt></i>:</span></td><td>the newly created dictionnary, or NULL if an error occured.</td></tr></tbody></table></div><h3><a name="xmlDictCreateSub" id="xmlDictCreateSub"></a>Function: xmlDictCreateSub</h3><pre class="programlisting"><a href="libxml-dict.html#xmlDictPtr">xmlDictPtr</a>	xmlDictCreateSub	(<a href="libxml-dict.html#xmlDictPtr">xmlDictPtr</a> sub)<br />
+</pre><p>Create a new dictionary, inheriting strings from the read-only dictionnary @sub. On lookup, strings are first searched in the new dictionnary, then in @sub, and if not found are created in the new dictionnary.</p>
+<div class="variablelist"><table border="0"><col align="left" /><tbody><tr><td><span class="term"><i><tt>sub</tt></i>:</span></td><td>an existing dictionnary</td></tr><tr><td><span class="term"><i><tt>Returns</tt></i>:</span></td><td>the newly created dictionnary, or NULL if an error occured.</td></tr></tbody></table></div><h3><a name="xmlDictFree" id="xmlDictFree"></a>Function: xmlDictFree</h3><pre class="programlisting">void	xmlDictFree			(<a href="libxml-dict.html#xmlDictPtr">xmlDictPtr</a> dict)<br />
 </pre><p>Free the hash @dict and its contents. The userdata is deallocated with @f if provided.</p>
 <div class="variablelist"><table border="0"><col align="left" /><tbody><tr><td><span class="term"><i><tt>dict</tt></i>:</span></td><td>the dictionnary</td></tr></tbody></table></div><h3><a name="xmlDictLookup" id="xmlDictLookup"></a>Function: xmlDictLookup</h3><pre class="programlisting">const <a href="libxml-xmlstring.html#xmlChar">xmlChar</a> *	xmlDictLookup		(<a href="libxml-dict.html#xmlDictPtr">xmlDictPtr</a> dict, <br />					 const <a href="libxml-xmlstring.html#xmlChar">xmlChar</a> * name, <br />					 int len)<br />
 </pre><p>Add the @name to the hash @dict if not present.</p>
diff --git a/doc/html/libxml-xpath.html b/doc/html/libxml-xpath.html
index 2afd717..137aef1 100644
--- a/doc/html/libxml-xpath.html
+++ b/doc/html/libxml-xpath.html
@@ -57,6 +57,7 @@
 </pre>
 <pre class="programlisting"><a href="libxml-xpath.html#xmlXPathObjectPtr">xmlXPathObjectPtr</a>	<a href="#xmlXPathConvertNumber">xmlXPathConvertNumber</a>	(<a href="libxml-xpath.html#xmlXPathObjectPtr">xmlXPathObjectPtr</a> val)</pre>
 <pre class="programlisting"><a href="libxml-xpath.html#xmlXPathObjectPtr">xmlXPathObjectPtr</a>	<a href="#xmlXPathConvertString">xmlXPathConvertString</a>	(<a href="libxml-xpath.html#xmlXPathObjectPtr">xmlXPathObjectPtr</a> val)</pre>
+<pre class="programlisting"><a href="libxml-xpath.html#xmlXPathCompExprPtr">xmlXPathCompExprPtr</a>	<a href="#xmlXPathCtxtCompile">xmlXPathCtxtCompile</a>	(<a href="libxml-xpath.html#xmlXPathContextPtr">xmlXPathContextPtr</a> ctxt, <br />						 const <a href="libxml-xmlstring.html#xmlChar">xmlChar</a> * str)</pre>
 <pre class="programlisting"><a href="libxml-xpath.html#xmlXPathObjectPtr">xmlXPathObjectPtr</a>	<a href="#xmlXPathEval">xmlXPathEval</a>	(const <a href="libxml-xmlstring.html#xmlChar">xmlChar</a> * str, <br />					 <a href="libxml-xpath.html#xmlXPathContextPtr">xmlXPathContextPtr</a> ctx)</pre>
 <pre class="programlisting"><a href="libxml-xpath.html#xmlXPathObjectPtr">xmlXPathObjectPtr</a>	<a href="#xmlXPathEvalExpression">xmlXPathEvalExpression</a>	(const <a href="libxml-xmlstring.html#xmlChar">xmlChar</a> * str, <br />						 <a href="libxml-xpath.html#xmlXPathContextPtr">xmlXPathContextPtr</a> ctxt)</pre>
 <pre class="programlisting">Function type: <a href="#xmlXPathEvalFunc">xmlXPathEvalFunc</a>
@@ -127,7 +128,8 @@
     void *	userData	: user specific data block
     <a href="libxml-xmlerror.html#xmlStructuredErrorFunc">xmlStructuredErrorFunc</a>	error	: the callback in case of errors
     <a href="libxml-xmlerror.html#xmlError">xmlError</a>	lastError	: the last error
-    <a href="libxml-tree.html#xmlNodePtr">xmlNodePtr</a>	debugNode	: the source node XSLT
+    <a href="libxml-tree.html#xmlNodePtr">xmlNodePtr</a>	debugNode	: the source node XSLT dictionnary
+    <a href="libxml-dict.html#xmlDictPtr">xmlDictPtr</a>	dict	: dictionnary if any
 }</pre><h3>Enum <a name="xmlXPathError" id="xmlXPathError">xmlXPathError</a></h3><pre class="programlisting">Enum xmlXPathError {
     <a name="XPATH_EXPRESSION_OK" id="XPATH_EXPRESSION_OK">XPATH_EXPRESSION_OK</a> = 0
     <a name="XPATH_NUMBER_ERROR" id="XPATH_NUMBER_ERROR">XPATH_NUMBER_ERROR</a> = 1
@@ -241,7 +243,9 @@
 </pre><p>Converts an existing object to its number() equivalent</p>
 <div class="variablelist"><table border="0"><col align="left" /><tbody><tr><td><span class="term"><i><tt>val</tt></i>:</span></td><td>an XPath object</td></tr><tr><td><span class="term"><i><tt>Returns</tt></i>:</span></td><td>the new object, the old one is freed (or the operation is done directly on @val)</td></tr></tbody></table></div><h3><a name="xmlXPathConvertString" id="xmlXPathConvertString"></a>Function: xmlXPathConvertString</h3><pre class="programlisting"><a href="libxml-xpath.html#xmlXPathObjectPtr">xmlXPathObjectPtr</a>	xmlXPathConvertString	(<a href="libxml-xpath.html#xmlXPathObjectPtr">xmlXPathObjectPtr</a> val)<br />
 </pre><p>Converts an existing object to its string() equivalent</p>
-<div class="variablelist"><table border="0"><col align="left" /><tbody><tr><td><span class="term"><i><tt>val</tt></i>:</span></td><td>an XPath object</td></tr><tr><td><span class="term"><i><tt>Returns</tt></i>:</span></td><td>the new object, the old one is freed (or the operation is done directly on @val)</td></tr></tbody></table></div><h3><a name="xmlXPathEval" id="xmlXPathEval"></a>Function: xmlXPathEval</h3><pre class="programlisting"><a href="libxml-xpath.html#xmlXPathObjectPtr">xmlXPathObjectPtr</a>	xmlXPathEval	(const <a href="libxml-xmlstring.html#xmlChar">xmlChar</a> * str, <br />					 <a href="libxml-xpath.html#xmlXPathContextPtr">xmlXPathContextPtr</a> ctx)<br />
+<div class="variablelist"><table border="0"><col align="left" /><tbody><tr><td><span class="term"><i><tt>val</tt></i>:</span></td><td>an XPath object</td></tr><tr><td><span class="term"><i><tt>Returns</tt></i>:</span></td><td>the new object, the old one is freed (or the operation is done directly on @val)</td></tr></tbody></table></div><h3><a name="xmlXPathCtxtCompile" id="xmlXPathCtxtCompile"></a>Function: xmlXPathCtxtCompile</h3><pre class="programlisting"><a href="libxml-xpath.html#xmlXPathCompExprPtr">xmlXPathCompExprPtr</a>	xmlXPathCtxtCompile	(<a href="libxml-xpath.html#xmlXPathContextPtr">xmlXPathContextPtr</a> ctxt, <br />						 const <a href="libxml-xmlstring.html#xmlChar">xmlChar</a> * str)<br />
+</pre><p></p>
+<div class="variablelist"><table border="0"><col align="left" /><tbody><tr><td><span class="term"><i><tt>ctxt</tt></i>:</span></td><td></td></tr><tr><td><span class="term"><i><tt>str</tt></i>:</span></td><td></td></tr><tr><td><span class="term"><i><tt>Returns</tt></i>:</span></td><td></td></tr></tbody></table></div><h3><a name="xmlXPathEval" id="xmlXPathEval"></a>Function: xmlXPathEval</h3><pre class="programlisting"><a href="libxml-xpath.html#xmlXPathObjectPtr">xmlXPathObjectPtr</a>	xmlXPathEval	(const <a href="libxml-xmlstring.html#xmlChar">xmlChar</a> * str, <br />					 <a href="libxml-xpath.html#xmlXPathContextPtr">xmlXPathContextPtr</a> ctx)<br />
 </pre><p>Evaluate the XPath Location Path in the given context.</p>
 <div class="variablelist"><table border="0"><col align="left" /><tbody><tr><td><span class="term"><i><tt>str</tt></i>:</span></td><td>the XPath expression</td></tr><tr><td><span class="term"><i><tt>ctx</tt></i>:</span></td><td>the XPath context</td></tr><tr><td><span class="term"><i><tt>Returns</tt></i>:</span></td><td>the <a href="libxml-xpath.html#xmlXPathObjectPtr">xmlXPathObjectPtr</a> resulting from the evaluation or NULL. the caller has to free the object.</td></tr></tbody></table></div><h3><a name="xmlXPathEvalExpression" id="xmlXPathEvalExpression"></a>Function: xmlXPathEvalExpression</h3><pre class="programlisting"><a href="libxml-xpath.html#xmlXPathObjectPtr">xmlXPathObjectPtr</a>	xmlXPathEvalExpression	(const <a href="libxml-xmlstring.html#xmlChar">xmlChar</a> * str, <br />						 <a href="libxml-xpath.html#xmlXPathContextPtr">xmlXPathContextPtr</a> ctxt)<br />
 </pre><p>Evaluate the XPath expression in the given context.</p>
diff --git a/doc/libxml2-api.xml b/doc/libxml2-api.xml
index 21d0d03..982fa63 100644
--- a/doc/libxml2-api.xml
+++ b/doc/libxml2-api.xml
@@ -367,8 +367,9 @@
      <exports symbol='xmlDictPtr' type='typedef'/>
      <exports symbol='xmlDictQLookup' type='function'/>
      <exports symbol='xmlDictReference' type='function'/>
-     <exports symbol='xmlDictSize' type='function'/>
+     <exports symbol='xmlDictCreateSub' type='function'/>
      <exports symbol='xmlDictCreate' type='function'/>
+     <exports symbol='xmlDictSize' type='function'/>
      <exports symbol='xmlDictLookup' type='function'/>
      <exports symbol='xmlDictFree' type='function'/>
      <exports symbol='xmlDictOwns' type='function'/>
@@ -2852,6 +2853,7 @@
      <exports symbol='xmlXPathCmpNodes' type='function'/>
      <exports symbol='xmlXPathCastBooleanToNumber' type='function'/>
      <exports symbol='xmlXPathCastToString' type='function'/>
+     <exports symbol='xmlXPathCtxtCompile' type='function'/>
      <exports symbol='xmlXPathCastStringToNumber' type='function'/>
      <exports symbol='xmlXPathAxisFunc' type='function'/>
      <exports symbol='xmlXPathCastToNumber' type='function'/>
@@ -5308,7 +5310,8 @@
       <field name='userData' type='void *' info=' user specific data block'/>
       <field name='error' type='xmlStructuredErrorFunc' info=' the callback in case of errors'/>
       <field name='lastError' type='xmlError' info=' the last error'/>
-      <field name='debugNode' type='xmlNodePtr' info=' the source node XSLT'/>
+      <field name='debugNode' type='xmlNodePtr' info=' the source node XSLT dictionnary'/>
+      <field name='dict' type='xmlDictPtr' info=' dictionnary if any'/>
     </struct>
     <typedef name='xmlXPathContextPtr' file='xpath' type='xmlXPathContext *'/>
     <typedef name='xmlXPathError' file='xpath' type='enum'/>
@@ -7503,7 +7506,12 @@
     </function>
     <function name='xmlDictCreate' file='dict'>
       <info>Create a new dictionary</info>
-      <return type='xmlDictPtr' info='the newly created object, or NULL if an error occured.'/>
+      <return type='xmlDictPtr' info='the newly created dictionnary, or NULL if an error occured.'/>
+    </function>
+    <function name='xmlDictCreateSub' file='dict'>
+      <info>Create a new dictionary, inheriting strings from the read-only dictionnary @sub. On lookup, strings are first searched in the new dictionnary, then in @sub, and if not found are created in the new dictionnary.</info>
+      <return type='xmlDictPtr' info='the newly created dictionnary, or NULL if an error occured.'/>
+      <arg name='sub' type='xmlDictPtr' info='an existing dictionnary'/>
     </function>
     <function name='xmlDictFree' file='dict'>
       <info>Free the hash @dict and its contents. The userdata is deallocated with @f if provided.</info>
@@ -13786,6 +13794,12 @@
       <arg name='ctxt' type='xmlXPathParserContextPtr' info='the XPath Parser context'/>
       <arg name='nargs' type='int' info='the number of arguments'/>
     </function>
+    <function name='xmlXPathCtxtCompile' file='xpath'>
+      <info></info>
+      <return type='xmlXPathCompExprPtr' info=''/>
+      <arg name='ctxt' type='xmlXPathContextPtr' info=''/>
+      <arg name='str' type='const xmlChar *' info=''/>
+    </function>
     <function name='xmlXPathDebugDumpCompExpr' file='xpathInternals'>
       <info>Dumps the tree of the compiled XPath expression.</info>
       <return type='void'/>
diff --git a/doc/libxml2-refs.xml b/doc/libxml2-refs.xml
index 5fb5c45..16e99c3 100644
--- a/doc/libxml2-refs.xml
+++ b/doc/libxml2-refs.xml
@@ -1396,6 +1396,7 @@
     <reference name='xmlDetectCharEncoding' href='html/libxml-encoding.html#xmlDetectCharEncoding'/>
     <reference name='xmlDict' href='html/libxml-dict.html#xmlDict'/>
     <reference name='xmlDictCreate' href='html/libxml-dict.html#xmlDictCreate'/>
+    <reference name='xmlDictCreateSub' href='html/libxml-dict.html#xmlDictCreateSub'/>
     <reference name='xmlDictFree' href='html/libxml-dict.html#xmlDictFree'/>
     <reference name='xmlDictLookup' href='html/libxml-dict.html#xmlDictLookup'/>
     <reference name='xmlDictOwns' href='html/libxml-dict.html#xmlDictOwns'/>
@@ -2648,6 +2649,7 @@
     <reference name='xmlXPathConvertNumber' href='html/libxml-xpath.html#xmlXPathConvertNumber'/>
     <reference name='xmlXPathConvertString' href='html/libxml-xpath.html#xmlXPathConvertString'/>
     <reference name='xmlXPathCountFunction' href='html/libxml-xpathInternals.html#xmlXPathCountFunction'/>
+    <reference name='xmlXPathCtxtCompile' href='html/libxml-xpath.html#xmlXPathCtxtCompile'/>
     <reference name='xmlXPathDebugDumpCompExpr' href='html/libxml-xpathInternals.html#xmlXPathDebugDumpCompExpr'/>
     <reference name='xmlXPathDebugDumpObject' href='html/libxml-xpathInternals.html#xmlXPathDebugDumpObject'/>
     <reference name='xmlXPathDifference' href='html/libxml-xpathInternals.html#xmlXPathDifference'/>
@@ -4288,6 +4290,7 @@
       <ref name='xmlDetectCharEncoding'/>
       <ref name='xmlDict'/>
       <ref name='xmlDictCreate'/>
+      <ref name='xmlDictCreateSub'/>
       <ref name='xmlDictFree'/>
       <ref name='xmlDictLookup'/>
       <ref name='xmlDictOwns'/>
@@ -5540,6 +5543,7 @@
       <ref name='xmlXPathConvertNumber'/>
       <ref name='xmlXPathConvertString'/>
       <ref name='xmlXPathCountFunction'/>
+      <ref name='xmlXPathCtxtCompile'/>
       <ref name='xmlXPathDebugDumpCompExpr'/>
       <ref name='xmlXPathDebugDumpObject'/>
       <ref name='xmlXPathDifference'/>
@@ -6026,6 +6030,7 @@
     </type>
     <type name='xmlDictPtr'>
       <ref name='xmlDictCreate'/>
+      <ref name='xmlDictCreateSub'/>
     </type>
     <type name='xmlDocPtr'>
       <ref name='xmlCopyDoc'/>
@@ -6347,6 +6352,7 @@
     </type>
     <type name='xmlXPathCompExprPtr'>
       <ref name='xmlXPathCompile'/>
+      <ref name='xmlXPathCtxtCompile'/>
     </type>
     <type name='xmlXPathContextPtr'>
       <ref name='xmlXPathNewContext'/>
@@ -6869,6 +6875,7 @@
       <ref name='xmlXPathCastStringToBoolean'/>
       <ref name='xmlXPathCastStringToNumber'/>
       <ref name='xmlXPathCompile'/>
+      <ref name='xmlXPathCtxtCompile'/>
       <ref name='xmlXPathEval'/>
       <ref name='xmlXPathEvalExpression'/>
       <ref name='xmlXPathFuncLookupFunc'/>
@@ -7525,6 +7532,7 @@
       <ref name='xmlPatterncompile'/>
     </type>
     <type name='xmlDictPtr'>
+      <ref name='xmlDictCreateSub'/>
       <ref name='xmlDictFree'/>
       <ref name='xmlDictLookup'/>
       <ref name='xmlDictOwns'/>
@@ -8653,6 +8661,7 @@
     </type>
     <type name='xmlXPathContextPtr'>
       <ref name='xmlXPathCompiledEval'/>
+      <ref name='xmlXPathCtxtCompile'/>
       <ref name='xmlXPathEval'/>
       <ref name='xmlXPathEvalExpression'/>
       <ref name='xmlXPathEvalPredicate'/>
@@ -9118,6 +9127,7 @@
     <file name='dict'>
       <ref name='xmlDict'/>
       <ref name='xmlDictCreate'/>
+      <ref name='xmlDictCreateSub'/>
       <ref name='xmlDictFree'/>
       <ref name='xmlDictLookup'/>
       <ref name='xmlDictOwns'/>
@@ -11497,6 +11507,7 @@
       <ref name='xmlXPathConvertFunc'/>
       <ref name='xmlXPathConvertNumber'/>
       <ref name='xmlXPathConvertString'/>
+      <ref name='xmlXPathCtxtCompile'/>
       <ref name='xmlXPathError'/>
       <ref name='xmlXPathEval'/>
       <ref name='xmlXPathEvalExpression'/>
@@ -18245,10 +18256,14 @@
         <word name='dictionary'>
           <ref name='_xmlParserCtxt'/>
           <ref name='xmlDictCreate'/>
+          <ref name='xmlDictCreateSub'/>
           <ref name='xmlDictReference'/>
         </word>
         <word name='dictionnary'>
           <ref name='_xmlParserCtxt'/>
+          <ref name='_xmlXPathContext'/>
+          <ref name='xmlDictCreate'/>
+          <ref name='xmlDictCreateSub'/>
           <ref name='xmlDictFree'/>
           <ref name='xmlDictLookup'/>
           <ref name='xmlDictOwns'/>
@@ -20347,6 +20362,9 @@
           <ref name='xmlNodeGetSpacePreserve'/>
           <ref name='xmlXPathNextAttribute'/>
         </word>
+        <word name='inheriting'>
+          <ref name='xmlDictCreateSub'/>
+        </word>
         <word name='inherits'>
           <ref name='xmlNewChild'/>
           <ref name='xmlNewTextChild'/>
@@ -21916,6 +21934,7 @@
         <word name='occured'>
           <ref name='xmlCtxtGetLastError'/>
           <ref name='xmlDictCreate'/>
+          <ref name='xmlDictCreateSub'/>
           <ref name='xmlGetLastError'/>
           <ref name='xmlHashCreate'/>
           <ref name='xmlListRemoveFirst'/>
@@ -23072,6 +23091,9 @@
           <ref name='xmlRegExecPushString'/>
           <ref name='xmlRegExecPushString2'/>
         </word>
+        <word name='read-only'>
+          <ref name='xmlDictCreateSub'/>
+        </word>
         <word name='readable'>
           <ref name='xmlStrEqual'/>
         </word>
@@ -23910,6 +23932,9 @@
           <ref name='xmlStrchr'/>
           <ref name='xmlStrstr'/>
         </word>
+        <word name='searched'>
+          <ref name='xmlDictCreateSub'/>
+        </word>
         <word name='section'>
           <ref name='HTML_PRESERVE_NODE'/>
           <ref name='xmlBuildURI'/>
@@ -24608,6 +24633,7 @@
         </word>
         <word name='strings'>
           <ref name='_xmlParserCtxt'/>
+          <ref name='xmlDictCreateSub'/>
           <ref name='xmlGetFeaturesList'/>
           <ref name='xmlPatterncompile'/>
           <ref name='xmlRegexpCompile'/>
diff --git a/include/libxml/dict.h b/include/libxml/dict.h
index e3390b3..874ba3d 100644
--- a/include/libxml/dict.h
+++ b/include/libxml/dict.h
@@ -29,6 +29,8 @@
  */
 XMLPUBFUN xmlDictPtr XMLCALL
 			xmlDictCreate	(void);
+XMLPUBFUN xmlDictPtr XMLCALL
+			xmlDictCreateSub(xmlDictPtr sub);
 XMLPUBFUN int XMLCALL
 			xmlDictReference(xmlDictPtr dict);
 XMLPUBFUN void XMLCALL			
diff --git a/include/libxml/xpath.h b/include/libxml/xpath.h
index 5172e93..41def0c 100644
--- a/include/libxml/xpath.h
+++ b/include/libxml/xpath.h
@@ -267,6 +267,9 @@
     xmlStructuredErrorFunc error;       /* the callback in case of errors */
     xmlError lastError;			/* the last error */
     xmlNodePtr debugNode;		/* the source node XSLT */
+
+    /* dictionnary */
+    xmlDictPtr dict;			/* dictionnary if any */
 };
 
 /*
@@ -450,6 +453,9 @@
  */
 XMLPUBFUN xmlXPathCompExprPtr XMLCALL 
 		    xmlXPathCompile		(const xmlChar *str);
+XMLPUBFUN xmlXPathCompExprPtr XMLCALL 
+		    xmlXPathCtxtCompile		(xmlXPathContextPtr ctxt,
+		    				 const xmlChar *str);
 XMLPUBFUN xmlXPathObjectPtr XMLCALL   
 		    xmlXPathCompiledEval	(xmlXPathCompExprPtr comp,
 						 xmlXPathContextPtr ctx);
diff --git a/testSAX.c b/testSAX.c
index b8db61b..4f00c53 100644
--- a/testSAX.c
+++ b/testSAX.c
@@ -49,6 +49,7 @@
 static int quiet = 0;
 static int nonull = 0;
 static int sax2 = 0;
+static int repeat = 0;
 static int callbacks = 0;
 
 xmlSAXHandler emptySAXHandlerStruct = {
@@ -913,6 +914,17 @@
 	     * Debug callback
 	     */
 	    callbacks = 0;
+	    if (repeat) {
+	        int i;
+		for (i = 0;i < 99;i++) {
+		    if (sax2)
+			res = xmlSAXUserParseFile(debugSAX2Handler, NULL,
+			                          filename);
+		    else
+			res = xmlSAXUserParseFile(debugSAXHandler, NULL,
+			                          filename);
+		}
+	    }
 	    if (sax2)
 	        res = xmlSAXUserParseFile(debugSAX2Handler, NULL, filename);
 	    else
@@ -956,7 +968,11 @@
 	else if ((!strcmp(argv[i], "-speed")) ||
 	         (!strcmp(argv[i], "--speed")))
 	    speed++;
-	else if ((!strcmp(argv[i], "-noent")) ||
+	else if ((!strcmp(argv[i], "-repeat")) ||
+	         (!strcmp(argv[i], "--repeat"))) {
+	    repeat++;
+	    quiet++;
+	} else if ((!strcmp(argv[i], "-noent")) ||
 	         (!strcmp(argv[i], "--noent")))
 	    noent++;
 	else if ((!strcmp(argv[i], "-quiet")) ||
diff --git a/xinclude.c b/xinclude.c
index 2697cfa..e4f9821 100644
--- a/xinclude.c
+++ b/xinclude.c
@@ -454,7 +454,12 @@
     }
     else {
         ret = NULL;
-        xmlFreeDoc(pctxt->myDoc);
+	if (pctxt->myDoc != NULL) {
+	    if ((ctxt->doc != NULL) && (ctxt->doc->dict != NULL) &&
+	        (pctxt->myDoc->dict == ctxt->doc->dict))
+		xmlDictReference(ctxt->doc->dict);
+	    xmlFreeDoc(pctxt->myDoc);
+	}
         pctxt->myDoc = NULL;
     }
     xmlFreeParserCtxt(pctxt);
diff --git a/xmlwriter.c b/xmlwriter.c
index 720c20d..3cda897 100644
--- a/xmlwriter.c
+++ b/xmlwriter.c
@@ -379,6 +379,8 @@
     if (writer->ctxt != NULL)
         xmlFreeParserCtxt(writer->ctxt);
 
+    if (writer->ichar != NULL)
+        xmlFree(writer->ichar);
     xmlFree(writer);
 }
 
@@ -4035,6 +4037,8 @@
   if (!str)
     return -1;
 
+  if (writer->ichar != NULL)
+      xmlFree(writer->ichar);
   writer->ichar = xmlStrdup (str);
   
   if (!writer->ichar)
diff --git a/xpath.c b/xpath.c
index 445a24b..6d6e336 100644
--- a/xpath.c
+++ b/xpath.c
@@ -420,6 +420,7 @@
     xmlXPathStepOp *steps;	/* ops for computation of this expression */
     int last;			/* index of last step in expression */
     xmlChar *expr;		/* the expression being computed */
+    xmlDictPtr dict;		/* the dictionnary to use if any */
 #ifdef DEBUG_EVAL_COUNTS
     int nb;
     xmlChar *string;
@@ -480,16 +481,27 @@
 
     if (comp == NULL)
         return;
-    for (i = 0; i < comp->nbStep; i++) {
-        op = &comp->steps[i];
-        if (op->value4 != NULL) {
-            if (op->op == XPATH_OP_VALUE)
-                xmlXPathFreeObject(op->value4);
-            else
-                xmlFree(op->value4);
-        }
-        if (op->value5 != NULL)
-            xmlFree(op->value5);
+    if (comp->dict == NULL) {
+	for (i = 0; i < comp->nbStep; i++) {
+	    op = &comp->steps[i];
+	    if (op->value4 != NULL) {
+		if (op->op == XPATH_OP_VALUE)
+		    xmlXPathFreeObject(op->value4);
+		else
+		    xmlFree(op->value4);
+	    }
+	    if (op->value5 != NULL)
+		xmlFree(op->value5);
+	}
+    } else {
+	for (i = 0; i < comp->nbStep; i++) {
+	    op = &comp->steps[i];
+	    if (op->value4 != NULL) {
+		if (op->op == XPATH_OP_VALUE)
+		    xmlXPathFreeObject(op->value4);
+	    }
+	}
+        xmlDictFree(comp->dict);
     }
     if (comp->steps != NULL) {
         xmlFree(comp->steps);
@@ -546,8 +558,25 @@
     comp->steps[comp->nbStep].value = value;
     comp->steps[comp->nbStep].value2 = value2;
     comp->steps[comp->nbStep].value3 = value3;
-    comp->steps[comp->nbStep].value4 = value4;
-    comp->steps[comp->nbStep].value5 = value5;
+    if ((comp->dict != NULL) &&
+        ((op == XPATH_OP_FUNCTION) || (op == XPATH_OP_VARIABLE) ||
+	 (op == XPATH_OP_COLLECT))) {
+        if (value4 != NULL) {
+	    comp->steps[comp->nbStep].value4 = 
+	        xmlDictLookup(comp->dict, value4, -1);
+	    xmlFree(value4);
+	} else
+	    comp->steps[comp->nbStep].value4 = NULL;
+        if (value5 != NULL) {
+	    comp->steps[comp->nbStep].value5 = 
+	        xmlDictLookup(comp->dict, value5, -1);
+	    xmlFree(value5);
+	} else
+	    comp->steps[comp->nbStep].value5 = NULL;
+    } else {
+	comp->steps[comp->nbStep].value4 = value4;
+	comp->steps[comp->nbStep].value5 = value5;
+    }
     comp->steps[comp->nbStep].cache = NULL;
     return(comp->nbStep++);
 }
@@ -3902,6 +3931,10 @@
 	xmlFree(ret);
 	return(NULL);
     }
+    if ((ctxt != NULL) && (ctxt->dict != NULL)) {
+        ret->comp->dict = ctxt->dict;
+	xmlDictReference(ret->comp->dict);
+    }
 
     return(ret);
 }
@@ -10880,6 +10913,56 @@
 }
 
 /**
+ * xmlXPathCtxtCompile:
+ * @ctxt: an XPath context
+ * @str:  the XPath expression
+ *
+ * Compile an XPath expression
+ *
+ * Returns the xmlXPathCompExprPtr resulting from the compilation or NULL.
+ *         the caller has to free the object.
+ */
+xmlXPathCompExprPtr
+xmlXPathCtxtCompile(xmlXPathContextPtr ctxt, const xmlChar *str) {
+    xmlXPathParserContextPtr pctxt;
+    xmlXPathCompExprPtr comp;
+
+    xmlXPathInit();
+
+    pctxt = xmlXPathNewParserContext(str, ctxt);
+    xmlXPathCompileExpr(pctxt);
+
+    if( pctxt->error != XPATH_EXPRESSION_OK )
+    {
+        xmlXPathFreeParserContext(pctxt);
+        return (0);
+    }
+
+    if (*pctxt->cur != 0) {
+	/* 
+	 * aleksey: in some cases this line prints *second* error message
+	 * (see bug #78858) and probably this should be fixed.
+	 * However, we are not sure that all error messages are printed
+	 * out in other places. It's not critical so we leave it as-is for now
+	 */
+	xmlXPatherror(pctxt, __FILE__, __LINE__, XPATH_EXPR_ERROR);
+	comp = NULL;
+    } else {
+	comp = pctxt->comp;
+	pctxt->comp = NULL;
+    }
+    xmlXPathFreeParserContext(pctxt);
+    if (comp != NULL) {
+	comp->expr = xmlStrdup(str);
+#ifdef DEBUG_EVAL_COUNTS
+	comp->string = xmlStrdup(str);
+	comp->nb = 0;
+#endif
+    }
+    return(comp);
+}
+
+/**
  * xmlXPathCompile:
  * @str:  the XPath expression
  *
@@ -10890,42 +10973,7 @@
  */
 xmlXPathCompExprPtr
 xmlXPathCompile(const xmlChar *str) {
-    xmlXPathParserContextPtr ctxt;
-    xmlXPathCompExprPtr comp;
-
-    xmlXPathInit();
-
-    ctxt = xmlXPathNewParserContext(str, NULL);
-    xmlXPathCompileExpr(ctxt);
-
-    if( ctxt->error != XPATH_EXPRESSION_OK )
-    {
-        xmlXPathFreeParserContext(ctxt);
-        return (0);
-    }
-
-    if (*ctxt->cur != 0) {
-	/* 
-	 * aleksey: in some cases this line prints *second* error message
-	 * (see bug #78858) and probably this should be fixed.
-	 * However, we are not sure that all error messages are printed
-	 * out in other places. It's not critical so we leave it as-is for now
-	 */
-	xmlXPatherror(ctxt, __FILE__, __LINE__, XPATH_EXPR_ERROR);
-	comp = NULL;
-    } else {
-	comp = ctxt->comp;
-	ctxt->comp = NULL;
-    }
-    xmlXPathFreeParserContext(ctxt);
-    if (comp != NULL) {
-	comp->expr = xmlStrdup(str);
-#ifdef DEBUG_EVAL_COUNTS
-	comp->string = xmlStrdup(str);
-	comp->nb = 0;
-#endif
-    }
-    return(comp);
+    return(xmlXPathCtxtCompile(NULL, str));
 }
 
 /**