augnemting the APIs, cleanups. cleanup bug #111005 added some missing

* include/libxml/relaxng.h relaxng.c include/libxml/xmlreader.h
  xmlreader.c: augnemting the APIs, cleanups.
* parser.c: cleanup bug #111005
* xmlIO.c: added some missing comments
Daniel
diff --git a/ChangeLog b/ChangeLog
index fa43615..2fcbd8e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Thu Apr 17 11:06:28 CEST 2003 Daniel Veillard <daniel@veillard.com>
+
+	* include/libxml/relaxng.h relaxng.c include/libxml/xmlreader.h
+	  xmlreader.c: augnemting the APIs, cleanups.
+	* parser.c: cleanup bug #111005
+	* xmlIO.c: added some missing comments
+
 Wed Apr 16 17:46:50 CEST 2003 Daniel Veillard <daniel@veillard.com>
 
 	* relaxng.c xmllint.c: more work on RelaxNG streaming validation
diff --git a/doc/libxml2-api.xml b/doc/libxml2-api.xml
index 6ee16a6..e2238fc 100644
--- a/doc/libxml2-api.xml
+++ b/doc/libxml2-api.xml
@@ -443,6 +443,7 @@
      <exports symbol='xmlAutomataNewOnceTrans'/>
      <exports symbol='xmlAutomataNewState'/>
      <exports symbol='xmlAutomataNewTransition'/>
+     <exports symbol='xmlAutomataNewTransition2'/>
      <exports symbol='xmlAutomataPtr'/>
      <exports symbol='xmlAutomataSetFinalState'/>
      <exports symbol='xmlAutomataState'/>
@@ -1138,6 +1139,7 @@
      <exports symbol='xmlTextReaderHasValue'/>
      <exports symbol='xmlTextReaderIsDefault'/>
      <exports symbol='xmlTextReaderIsEmptyElement'/>
+     <exports symbol='xmlTextReaderIsValid'/>
      <exports symbol='xmlTextReaderLocalName'/>
      <exports symbol='xmlTextReaderLocatorBaseURI'/>
      <exports symbol='xmlTextReaderLocatorLineNumber'/>
@@ -1163,6 +1165,8 @@
      <exports symbol='xmlTextReaderReadOuterXml'/>
      <exports symbol='xmlTextReaderReadState'/>
      <exports symbol='xmlTextReaderReadString'/>
+     <exports symbol='xmlTextReaderRelaxNGSetSchema'/>
+     <exports symbol='xmlTextReaderRelaxNGValidate'/>
      <exports symbol='xmlTextReaderSetErrorHandler'/>
      <exports symbol='xmlTextReaderSetParserProp'/>
      <exports symbol='xmlTextReaderValue'/>
@@ -1182,6 +1186,7 @@
      <exports symbol='XML_RELAXNG_ERR_ELEMNAME'/>
      <exports symbol='XML_RELAXNG_ERR_ELEMNONS'/>
      <exports symbol='XML_RELAXNG_ERR_ELEMNOTEMPTY'/>
+     <exports symbol='XML_RELAXNG_ERR_ELEMWRONG'/>
      <exports symbol='XML_RELAXNG_ERR_ELEMWRONGNS'/>
      <exports symbol='XML_RELAXNG_ERR_EXTRACONTENT'/>
      <exports symbol='XML_RELAXNG_ERR_EXTRADATA'/>
@@ -1201,6 +1206,7 @@
      <exports symbol='XML_RELAXNG_ERR_NOGRAMMAR'/>
      <exports symbol='XML_RELAXNG_ERR_NOSTATE'/>
      <exports symbol='XML_RELAXNG_ERR_NOTELEM'/>
+     <exports symbol='XML_RELAXNG_ERR_TEXTWRONG'/>
      <exports symbol='XML_RELAXNG_ERR_TYPE'/>
      <exports symbol='XML_RELAXNG_ERR_TYPECMP'/>
      <exports symbol='XML_RELAXNG_ERR_TYPEVAL'/>
@@ -1214,6 +1220,7 @@
      <exports symbol='xmlRelaxNGFree'/>
      <exports symbol='xmlRelaxNGFreeParserCtxt'/>
      <exports symbol='xmlRelaxNGFreeValidCtxt'/>
+     <exports symbol='xmlRelaxNGNewDocParserCtxt'/>
      <exports symbol='xmlRelaxNGNewMemParserCtxt'/>
      <exports symbol='xmlRelaxNGNewParserCtxt'/>
      <exports symbol='xmlRelaxNGNewValidCtxt'/>
@@ -1227,6 +1234,10 @@
      <exports symbol='xmlRelaxNGValidCtxtPtr'/>
      <exports symbol='xmlRelaxNGValidErr'/>
      <exports symbol='xmlRelaxNGValidateDoc'/>
+     <exports symbol='xmlRelaxNGValidateFullElement'/>
+     <exports symbol='xmlRelaxNGValidatePopElement'/>
+     <exports symbol='xmlRelaxNGValidatePushCData'/>
+     <exports symbol='xmlRelaxNGValidatePushElement'/>
      <exports symbol='xmlRelaxNGValidityErrorFunc'/>
      <exports symbol='xmlRelaxNGValidityWarningFunc'/>
     </file>
@@ -1722,6 +1733,7 @@
      <exports symbol='xmlRegExecCtxt'/>
      <exports symbol='xmlRegExecCtxtPtr'/>
      <exports symbol='xmlRegExecPushString'/>
+     <exports symbol='xmlRegExecPushString2'/>
      <exports symbol='xmlRegFreeExecCtxt'/>
      <exports symbol='xmlRegFreeRegexp'/>
      <exports symbol='xmlRegNewExecCtxt'/>
@@ -2527,6 +2539,7 @@
     <enum name='XML_RELAXNG_ERR_ELEMNAME' file='relaxng' value='13' type='xmlRelaxNGValidErr'/>
     <enum name='XML_RELAXNG_ERR_ELEMNONS' file='relaxng' value='15' type='xmlRelaxNGValidErr'/>
     <enum name='XML_RELAXNG_ERR_ELEMNOTEMPTY' file='relaxng' value='21' type='xmlRelaxNGValidErr'/>
+    <enum name='XML_RELAXNG_ERR_ELEMWRONG' file='relaxng' value='38' type='xmlRelaxNGValidErr'/>
     <enum name='XML_RELAXNG_ERR_ELEMWRONGNS' file='relaxng' value='17' type='xmlRelaxNGValidErr'/>
     <enum name='XML_RELAXNG_ERR_EXTRACONTENT' file='relaxng' value='26' type='xmlRelaxNGValidErr'/>
     <enum name='XML_RELAXNG_ERR_EXTRADATA' file='relaxng' value='35' type='xmlRelaxNGValidErr'/>
@@ -2546,6 +2559,7 @@
     <enum name='XML_RELAXNG_ERR_NOGRAMMAR' file='relaxng' value='34' type='xmlRelaxNGValidErr'/>
     <enum name='XML_RELAXNG_ERR_NOSTATE' file='relaxng' value='6' type='xmlRelaxNGValidErr'/>
     <enum name='XML_RELAXNG_ERR_NOTELEM' file='relaxng' value='23' type='xmlRelaxNGValidErr'/>
+    <enum name='XML_RELAXNG_ERR_TEXTWRONG' file='relaxng' value='39' type='xmlRelaxNGValidErr'/>
     <enum name='XML_RELAXNG_ERR_TYPE' file='relaxng' value='2' type='xmlRelaxNGValidErr'/>
     <enum name='XML_RELAXNG_ERR_TYPECMP' file='relaxng' value='5' type='xmlRelaxNGValidErr'/>
     <enum name='XML_RELAXNG_ERR_TYPEVAL' file='relaxng' value='3' type='xmlRelaxNGValidErr'/>
@@ -4456,6 +4470,16 @@
       <arg name='token' type='const xmlChar *' info='the input string associated to that transition'/>
       <arg name='data' type='void *' info='data passed to the callback function if the transition is activated'/>
     </function>
+    <function name='xmlAutomataNewTransition2' file='xmlautomata'>
+      <info>If @to is NULL, this create first a new target state in the automata and then adds a transition from the @from state to the target state activated by the value of @token</info>
+      <return type='xmlAutomataStatePtr' info='the target state or NULL in case of error'/>
+      <arg name='am' type='xmlAutomataPtr' info='an automata'/>
+      <arg name='from' type='xmlAutomataStatePtr' info='the starting point of the transition'/>
+      <arg name='to' type='xmlAutomataStatePtr' info='the target point of the transition or NULL'/>
+      <arg name='token' type='const xmlChar *' info='the first input string associated to that transition'/>
+      <arg name='token2' type='const xmlChar *' info='the second input string associated to that transition'/>
+      <arg name='data' type='void *' info='data passed to the callback function if the transition is activated'/>
+    </function>
     <function name='xmlAutomataSetFinalState' file='xmlautomata'>
       <info>Makes that state a final state</info>
       <return type='int' info='0 or -1 in case of error'/>
@@ -6898,8 +6922,8 @@
     </function>
     <function name='xmlNormalizeWindowsPath' file='xmlIO'>
       <info>This function is obsolete. Please see xmlURIFromPath in uri.c for a better solution.</info>
-      <return type='xmlChar *' info=''/>
-      <arg name='path' type='const xmlChar *' info=''/>
+      <return type='xmlChar *' info='a canonicalized version of the path'/>
+      <arg name='path' type='const xmlChar *' info='the input file path'/>
     </function>
     <function name='xmlOutputBufferClose' file='xmlIO'>
       <info>flushes and close the output I/O channel and free up all the associated resources</info>
@@ -7551,6 +7575,14 @@
       <arg name='value' type='const xmlChar *' info='a string token input'/>
       <arg name='data' type='void *' info='data associated to the token to reuse in callbacks'/>
     </function>
+    <function name='xmlRegExecPushString2' file='xmlregexp'>
+      <info>Push one input token in the execution context</info>
+      <return type='int' info='1 if the regexp reached a final state, 0 if non-final, and a negative value in case of error.'/>
+      <arg name='exec' type='xmlRegExecCtxtPtr' info='a regexp execution context or NULL to indicate the end'/>
+      <arg name='value' type='const xmlChar *' info='the first string token input'/>
+      <arg name='value2' type='const xmlChar *' info='the second string token input'/>
+      <arg name='data' type='void *' info='data associated to the token to reuse in callbacks'/>
+    </function>
     <function name='xmlRegFreeExecCtxt' file='xmlregexp'>
       <info>Free the structures associated to a regular expression evaulation context.</info>
       <return type='void'/>
@@ -7664,6 +7696,11 @@
       <return type='void'/>
       <arg name='ctxt' type='xmlRelaxNGValidCtxtPtr' info='the schema validation context'/>
     </function>
+    <function name='xmlRelaxNGNewDocParserCtxt' file='relaxng'>
+      <info>Create an XML RelaxNGs parser context for that document. Note: since the process of compiling a RelaxNG schemas modifies the document, the @doc parameter is duplicated internally.</info>
+      <return type='xmlRelaxNGParserCtxtPtr' info='the parser context or NULL in case of error'/>
+      <arg name='doc' type='xmlDocPtr' info='a preparsed document tree'/>
+    </function>
     <function name='xmlRelaxNGNewMemParserCtxt' file='relaxng'>
       <info>Create an XML RelaxNGs parse context for that memory buffer expected to contain an XML RelaxNGs file.</info>
       <return type='xmlRelaxNGParserCtxtPtr' info='the parser context or NULL in case of error'/>
@@ -7707,6 +7744,34 @@
       <arg name='ctxt' type='xmlRelaxNGValidCtxtPtr' info='a Relax-NG validation context'/>
       <arg name='doc' type='xmlDocPtr' info='a parsed document tree'/>
     </function>
+    <function name='xmlRelaxNGValidateFullElement' file='relaxng'>
+      <info>Validate a full subtree when xmlRelaxNGValidatePushElement() returned 0 and the content of the node has been expanded.</info>
+      <return type='int' info='1 if no validation problem was found or -1 in case of error.'/>
+      <arg name='ctxt' type='xmlRelaxNGValidCtxtPtr' info='the validation context'/>
+      <arg name='doc' type='xmlDocPtr' info='a document instance'/>
+      <arg name='elem' type='xmlNodePtr' info='an element instance'/>
+    </function>
+    <function name='xmlRelaxNGValidatePopElement' file='relaxng'>
+      <info>Pop the element end from the RelaxNG validation stack.</info>
+      <return type='int' info='1 if no validation problem was found or 0 otherwise'/>
+      <arg name='ctxt' type='xmlRelaxNGValidCtxtPtr' info='the RelaxNG validation context'/>
+      <arg name='doc' type='xmlDocPtr' info='a document instance'/>
+      <arg name='elem' type='xmlNodePtr' info='an element instance'/>
+    </function>
+    <function name='xmlRelaxNGValidatePushCData' file='relaxng'>
+      <info>check the CData parsed for validation in the current stack</info>
+      <return type='int' info='1 if no validation problem was found or -1 otherwise'/>
+      <arg name='ctxt' type='xmlRelaxNGValidCtxtPtr' info='the RelaxNG validation context'/>
+      <arg name='data' type='const xmlChar *' info='some character data read'/>
+      <arg name='len' type='int' info='the lenght of the data'/>
+    </function>
+    <function name='xmlRelaxNGValidatePushElement' file='relaxng'>
+      <info>Push a new element start on the RelaxNG validation stack.</info>
+      <return type='int' info='1 if no validation problem was found or 0 if validating the element requires a full node, and -1 in case of error.'/>
+      <arg name='ctxt' type='xmlRelaxNGValidCtxtPtr' info='the validation context'/>
+      <arg name='doc' type='xmlDocPtr' info='a document instance'/>
+      <arg name='elem' type='xmlNodePtr' info='an element instance'/>
+    </function>
     <functype name='xmlRelaxNGValidityErrorFunc' file='relaxng'>
       <info></info>
       <return type='void'/>
@@ -8363,6 +8428,11 @@
       <return type='int' info='1 if empty, 0 if not and -1 in case of error'/>
       <arg name='reader' type='xmlTextReaderPtr' info='the xmlTextReaderPtr used'/>
     </function>
+    <function name='xmlTextReaderIsValid' file='xmlreader'>
+      <info>Retrieve the validity status from the parser context</info>
+      <return type='int' info='the flag value 1 if valid, 0 if no, and -1 in case of error'/>
+      <arg name='reader' type='xmlTextReaderPtr' info='the xmlTextReaderPtr used'/>
+    </function>
     <function name='xmlTextReaderLocalName' file='xmlreader'>
       <info>The local name of the node.</info>
       <return type='xmlChar *' info='the local name or NULL if not available'/>
@@ -8483,6 +8553,18 @@
       <return type='xmlChar *' info='a string containing the contents of the Element or Text node, or NULL if the reader is positioned on any other type of node. The string must be deallocated by the caller.'/>
       <arg name='reader' type='xmlTextReaderPtr' info='the xmlTextReaderPtr used'/>
     </function>
+    <function name='xmlTextReaderRelaxNGSetSchema' file='xmlreader'>
+      <info>Use RelaxNG to validate the document as it is processed. Activation is only possible before the first Read(). if @schema is NULL, then RelaxNG validation is desactivated. @ The @schema should not be freed until the reader is deallocated or its use has been deactivated.</info>
+      <return type='int' info='0 in case the RelaxNG validation could be (des)activated and -1 in case of error.'/>
+      <arg name='reader' type='xmlTextReaderPtr' info='the xmlTextReaderPtr used'/>
+      <arg name='schema' type='xmlRelaxNGPtr' info='a precompiled RelaxNG schema'/>
+    </function>
+    <function name='xmlTextReaderRelaxNGValidate' file='xmlreader'>
+      <info>Use RelaxNG to validate the document as it is processed. Activation is only possible before the first Read(). if @rng is NULL, then RelaxNG validation is desactivated.</info>
+      <return type='int' info='0 in case the RelaxNG validation could be (des)activated and -1 in case of error.'/>
+      <arg name='reader' type='xmlTextReaderPtr' info='the xmlTextReaderPtr used'/>
+      <arg name='rng' type='const char *' info='the path to a RelaxNG schema or NULL'/>
+    </function>
     <function name='xmlTextReaderSetErrorHandler' file='xmlreader'>
       <info>Register a callback function that will be called on error and warnings.  If @f is NULL, the default error and warning handlers are restored.</info>
       <return type='void'/>
diff --git a/include/libxml/relaxng.h b/include/libxml/relaxng.h
index a21f92c..46848cb 100644
--- a/include/libxml/relaxng.h
+++ b/include/libxml/relaxng.h
@@ -81,6 +81,8 @@
 xmlRelaxNGParserCtxtPtr xmlRelaxNGNewParserCtxt	(const char *URL);
 xmlRelaxNGParserCtxtPtr xmlRelaxNGNewMemParserCtxt(const char *buffer,
 						 int size);
+xmlRelaxNGParserCtxtPtr xmlRelaxNGNewDocParserCtxt(xmlDocPtr doc);
+
 void		xmlRelaxNGFreeParserCtxt	(xmlRelaxNGParserCtxtPtr ctxt);
 void		xmlRelaxNGSetParserErrors(xmlRelaxNGParserCtxtPtr ctxt,
 					 xmlRelaxNGValidityErrorFunc err,
diff --git a/include/libxml/xmlreader.h b/include/libxml/xmlreader.h
index 1ced8b8..99396b7 100644
--- a/include/libxml/xmlreader.h
+++ b/include/libxml/xmlreader.h
@@ -11,6 +11,9 @@
 
 #include <libxml/tree.h>
 #include <libxml/xmlIO.h>
+#ifdef LIBXML_SCHEMAS_ENABLED
+#include <libxml/relaxng.h>
+#endif
 
 #ifdef __cplusplus
 extern "C" {
@@ -112,6 +115,8 @@
 #ifdef LIBXML_SCHEMAS_ENABLED
 int		xmlTextReaderRelaxNGValidate	(xmlTextReaderPtr reader,
 						 const char *rng);
+int		xmlTextReaderRelaxNGSetSchema	(xmlTextReaderPtr reader,
+						 xmlRelaxNGPtr schema);
 #endif
 
 /*
diff --git a/parser.c b/parser.c
index 333e273..5c7af3d 100644
--- a/parser.c
+++ b/parser.c
@@ -10273,7 +10273,6 @@
 xmlSAXParseEntity(xmlSAXHandlerPtr sax, const char *filename) {
     xmlDocPtr ret;
     xmlParserCtxtPtr ctxt;
-    char *directory = NULL;
 
     ctxt = xmlCreateFileParserCtxt(filename);
     if (ctxt == NULL) {
@@ -10286,9 +10285,6 @@
         ctxt->userData = NULL;
     }
 
-    if ((ctxt->directory == NULL) && (directory == NULL))
-        directory = xmlParserGetDirectory(filename);
-
     xmlParseExtParsedEnt(ctxt);
 
     if (ctxt->wellFormed)
diff --git a/python/libxml2class.txt b/python/libxml2class.txt
index 950397d..1e6808a 100644
--- a/python/libxml2class.txt
+++ b/python/libxml2class.txt
@@ -474,7 +474,11 @@
     parameterEntity()
 
     # functions from module relaxng
+    relaxNGNewDocParserCtxt()
     relaxNGValidateDoc()
+    relaxNGValidateFullElement()
+    relaxNGValidatePopElement()
+    relaxNGValidatePushElement()
 
     # functions from module tree
     copyDoc()
@@ -606,6 +610,7 @@
     HasValue()
     IsDefault()
     IsEmptyElement()
+    IsValid()
     LocalName()
     LookupNamespace()
     MoveToAttribute()
@@ -627,6 +632,8 @@
     ReadOuterXml()
     ReadState()
     ReadString()
+    RelaxNGSetSchema()
+    RelaxNGValidate()
     SetParserProp()
     Value()
     XmlLang()
@@ -654,6 +661,7 @@
 
     # functions from module relaxng
     relaxNGFreeValidCtxt()
+    relaxNGValidatePushCData()
 Class xpathParserContext()
     # accessors
     context()
diff --git a/relaxng.c b/relaxng.c
index b7a0711..b6961fd 100644
--- a/relaxng.c
+++ b/relaxng.c
@@ -6510,6 +6510,39 @@
 }
 
 /**
+ * xmlRelaxNGNewDocParserCtxt:
+ * @doc:  a preparsed document tree
+ *
+ * Create an XML RelaxNGs parser context for that document.
+ * Note: since the process of compiling a RelaxNG schemas modifies the
+ *       document, the @doc parameter is duplicated internally.
+ *
+ * Returns the parser context or NULL in case of error
+ */
+xmlRelaxNGParserCtxtPtr
+xmlRelaxNGNewDocParserCtxt(xmlDocPtr doc) {
+    xmlRelaxNGParserCtxtPtr ret;
+    xmlDocPtr copy;
+
+    if (doc == NULL)
+	return(NULL);
+    copy = xmlCopyDoc(doc, 1);
+    if (copy == NULL)
+        return(NULL);
+
+    ret = (xmlRelaxNGParserCtxtPtr) xmlMalloc(sizeof(xmlRelaxNGParserCtxt));
+    if (ret == NULL) {
+	xmlGenericError(xmlGenericErrorContext,
+		"Failed to allocate new schama parser context\n");
+        return (NULL);
+    }
+    memset(ret, 0, sizeof(xmlRelaxNGParserCtxt));
+    ret->document = copy;
+    ret->userData = xmlGenericErrorContext;
+    return (ret);
+}
+
+/**
  * xmlRelaxNGFreeParserCtxt:
  * @ctxt:  the schema parser context
  *
@@ -6522,7 +6555,7 @@
     if (ctxt->URL != NULL)
 	xmlFree(ctxt->URL);
     if (ctxt->doc != NULL)
-	xmlFreeDoc(ctxt->document);
+	xmlFreeDoc(ctxt->doc);
     if (ctxt->interleaves != NULL)
         xmlHashFree(ctxt->interleaves, NULL);
     if (ctxt->documents != NULL)
@@ -7159,6 +7192,8 @@
 	}
 	doc->URL = xmlStrdup(BAD_CAST "in_memory_buffer");
 	ctxt->URL = xmlStrdup(BAD_CAST "in_memory_buffer");
+    } else if (ctxt->document != NULL) {
+        doc = ctxt->document;
     } else {
 	if (ctxt->error != NULL)
 	    ctxt->error(ctxt->userData,
@@ -7845,7 +7880,8 @@
  *         element requires a full node, and -1 in case of error.
  */
 int
-xmlRelaxNGValidatePushElement(xmlRelaxNGValidCtxtPtr ctxt, xmlDocPtr doc,
+xmlRelaxNGValidatePushElement(xmlRelaxNGValidCtxtPtr ctxt,
+                              xmlDocPtr doc ATTRIBUTE_UNUSED,
                               xmlNodePtr elem)
 {
     int ret = 1;
@@ -7924,7 +7960,8 @@
  */
 int
 xmlRelaxNGValidatePushCData(xmlRelaxNGValidCtxtPtr ctxt,
-                            const xmlChar * data, int len)
+                            const xmlChar * data,
+			    int len ATTRIBUTE_UNUSED)
 {
     int ret = 1;
 
@@ -7945,7 +7982,7 @@
 
     ret = xmlRegExecPushString(ctxt->elem, BAD_CAST "#text", ctxt);
     if (ret < 0) {
-        VALID_ERR2(XML_RELAXNG_ERR_TEXTWRONG, " TODO ");
+        VALID_ERR2(XML_RELAXNG_ERR_TEXTWRONG, BAD_CAST " TODO ");
 #ifdef DEBUG_PROGRESSIVE
 	xmlGenericError(xmlGenericErrorContext, "CDATA failed\n");
 #endif
@@ -8013,7 +8050,8 @@
  * returns 1 if no validation problem was found or -1 in case of error.
  */
 int
-xmlRelaxNGValidateFullElement(xmlRelaxNGValidCtxtPtr ctxt, xmlDocPtr doc,
+xmlRelaxNGValidateFullElement(xmlRelaxNGValidCtxtPtr ctxt,
+                              xmlDocPtr doc ATTRIBUTE_UNUSED,
 			      xmlNodePtr elem) {
     int ret;
     xmlRelaxNGValidStatePtr state;
diff --git a/xmlIO.c b/xmlIO.c
index 82416f2..f137d66 100644
--- a/xmlIO.c
+++ b/xmlIO.c
@@ -124,9 +124,12 @@
 
 /**
  * xmlNormalizeWindowsPath:
+ * @path: the input file path
  *
  * This function is obsolete. Please see xmlURIFromPath in uri.c for
  * a better solution.
+ *
+ * Returns a canonicalized version of the path
  */
 xmlChar *
 xmlNormalizeWindowsPath(const xmlChar *path)
diff --git a/xmlreader.c b/xmlreader.c
index 54a3b94..73e5deb 100644
--- a/xmlreader.c
+++ b/xmlreader.c
@@ -1031,7 +1031,7 @@
  *         string must be deallocated by the caller.
  */
 xmlChar *
-xmlTextReaderReadInnerXml(xmlTextReaderPtr reader) {
+xmlTextReaderReadInnerXml(xmlTextReaderPtr reader ATTRIBUTE_UNUSED) {
     TODO
     return(NULL);
 }
@@ -1047,7 +1047,7 @@
  *         string must be deallocated by the caller.
  */
 xmlChar *
-xmlTextReaderReadOuterXml(xmlTextReaderPtr reader) {
+xmlTextReaderReadOuterXml(xmlTextReaderPtr reader ATTRIBUTE_UNUSED) {
     TODO
     return(NULL);
 }
@@ -1063,7 +1063,7 @@
  *         The string must be deallocated by the caller.
  */
 xmlChar *
-xmlTextReaderReadString(xmlTextReaderPtr reader) {
+xmlTextReaderReadString(xmlTextReaderPtr reader ATTRIBUTE_UNUSED) {
     TODO
     return(NULL);
 }
@@ -2502,6 +2502,58 @@
 }
 
 /**
+ * xmlTextReaderRelaxNGSetSchema:
+ * @reader:  the xmlTextReaderPtr used
+ * @schema:  a precompiled RelaxNG schema
+ *
+ * Use RelaxNG to validate the document as it is processed.
+ * Activation is only possible before the first Read().
+ * if @schema is NULL, then RelaxNG validation is desactivated.
+ @ The @schema should not be freed until the reader is deallocated
+ * or its use has been deactivated.
+ *
+ * Returns 0 in case the RelaxNG validation could be (des)activated and
+ *         -1 in case of error.
+ */
+int
+xmlTextReaderRelaxNGSetSchema(xmlTextReaderPtr reader, xmlRelaxNGPtr schema) {
+    if (schema == NULL) {
+        if (reader->rngSchemas != NULL) {
+	    xmlRelaxNGFree(reader->rngSchemas);
+	    reader->rngSchemas = NULL;
+	}
+        if (reader->rngValidCtxt != NULL) {
+	    xmlRelaxNGFreeValidCtxt(reader->rngValidCtxt);
+	    reader->rngValidCtxt = NULL;
+        }
+	return(0);
+    }
+    if (reader->mode != XML_TEXTREADER_MODE_INITIAL)
+	return(-1);
+    if (reader->rngSchemas != NULL) {
+	xmlRelaxNGFree(reader->rngSchemas);
+	reader->rngSchemas = NULL;
+    }
+    if (reader->rngValidCtxt != NULL) {
+	xmlRelaxNGFreeValidCtxt(reader->rngValidCtxt);
+	reader->rngValidCtxt = NULL;
+    }
+    reader->rngValidCtxt = xmlRelaxNGNewValidCtxt(schema);
+    if (reader->rngValidCtxt == NULL)
+        return(-1);
+    if (reader->errorFunc != NULL) {
+	xmlRelaxNGSetValidErrors(reader->rngValidCtxt,
+			 (xmlRelaxNGValidityErrorFunc)reader->errorFunc,
+			 (xmlRelaxNGValidityWarningFunc) reader->errorFunc,
+			 reader->errorFuncArg);
+    }
+    reader->rngValidErrors = 0;
+    reader->rngFullNode = NULL;
+    reader->validate = XML_TEXTREADER_VALIDATE_RNG;
+    return(0);
+}
+
+/**
  * xmlTextReaderRelaxNGValidate:
  * @reader:  the xmlTextReaderPtr used
  * @rng:  the path to a RelaxNG schema or NULL
@@ -2533,6 +2585,14 @@
     }
     if (reader->mode != XML_TEXTREADER_MODE_INITIAL)
 	return(-1);
+    if (reader->rngSchemas != NULL) {
+	xmlRelaxNGFree(reader->rngSchemas);
+	reader->rngSchemas = NULL;
+    }
+    if (reader->rngValidCtxt != NULL) {
+	xmlRelaxNGFreeValidCtxt(reader->rngValidCtxt);
+	reader->rngValidCtxt = NULL;
+    }
     ctxt = xmlRelaxNGNewParserCtxt(rng);
     if (reader->errorFunc != NULL) {
 	xmlRelaxNGSetParserErrors(ctxt,