[xml] XInclude _private patch [Was: What is the _private field actually for?]



Hi Daniel,

  Hum, yeah, I don't see how to do this except by adding yet another API
with yet another extra data, not nice but I don't see a workaround.

Here is a new XInclude function that passes in a value that will be stored in the XInclude context and then passed into the parser context.

Best regards,

Michael

Index: include/libxml/xinclude.h
===================================================================
RCS file: /cvs/gnome/libxml2/include/libxml/xinclude.h,v
retrieving revision 1.13
diff -u -r1.13 xinclude.h
--- include/libxml/xinclude.h   27 Jun 2004 12:08:10 -0000      1.13
+++ include/libxml/xinclude.h   29 Sep 2006 05:46:44 -0000
@@ -95,6 +95,10 @@
                xmlXIncludeProcessFlags (xmlDocPtr doc,
                                         int flags);
 XMLPUBFUN int XMLCALL  
+               xmlXIncludeProcessFlagsData(xmlDocPtr doc,
+                                        int flags,
+                                        void *data);
+XMLPUBFUN int XMLCALL  
                xmlXIncludeProcessTree  (xmlNodePtr tree);
 XMLPUBFUN int XMLCALL  
                xmlXIncludeProcessTreeFlags(xmlNodePtr tree,
Index: xinclude.c
===================================================================
RCS file: /cvs/gnome/libxml2/xinclude.c,v
retrieving revision 1.84
diff -u -r1.84 xinclude.c
--- xinclude.c  6 Jun 2006 08:21:41 -0000       1.84
+++ xinclude.c  29 Sep 2006 05:46:45 -0000
@@ -82,6 +82,8 @@
     int                legacy; /* using XINCLUDE_OLD_NS */
int parseFlags; /* the flags used for parsing XML documents */
     xmlChar *           base; /* the current xml:base */
+
+    void            *_private; /* application data */
 };

 static int
@@ -427,6 +429,12 @@
        xmlXIncludeErrMemory(ctxt, NULL, "cannot allocate parser context");
        return(NULL);
     }
+
+    /*
+     * pass in the application data to the parser context.
+     */
+    pctxt->_private = ctxt->_private;
+
     /*
      * try to ensure that new documents included are actually
      * built with the same dictionary as the including document.
@@ -2409,9 +2417,10 @@
 }

 /**
- * xmlXIncludeProcessFlags:
+ * xmlXIncludeProcessFlagsData:
  * @doc: an XML document
  * @flags: a set of xmlParserOption used for parsing XML includes
+ * @data: application data that will be passed to the parser context
  *
  * Implement the XInclude substitution on the XML document @doc
  *
@@ -2419,7 +2428,7 @@
  *    or the number of substitutions done.
  */
 int
-xmlXIncludeProcessFlags(xmlDocPtr doc, int flags) {
+xmlXIncludeProcessFlagsData(xmlDocPtr doc, int flags, void *data) {
     xmlXIncludeCtxtPtr ctxt;
     xmlNodePtr tree;
     int ret = 0;
@@ -2432,6 +2441,7 @@
     ctxt = xmlXIncludeNewContext(doc);
     if (ctxt == NULL)
        return(-1);
+    ctxt->_private = data;
     ctxt->base = xmlStrdup((xmlChar *)doc->URL);
     xmlXIncludeSetFlags(ctxt, flags);
     ret = xmlXIncludeDoProcess(ctxt, doc, tree);
@@ -2440,6 +2450,21 @@

     xmlXIncludeFreeContext(ctxt);
     return(ret);
+}
+
+/**
+ * xmlXIncludeProcessFlags:
+ * @doc: an XML document
+ * @flags: a set of xmlParserOption used for parsing XML includes
+ *
+ * Implement the XInclude substitution on the XML document @doc
+ *
+ * Returns 0 if no substitution were done, -1 if some processing failed
+ *    or the number of substitutions done.
+ */
+int
+xmlXIncludeProcessFlags(xmlDocPtr doc, int flags) {
+    return xmlXIncludeProcessFlagsData(doc, flags, NULL);
 }

 /**


--
Print XML with Prince!
http://www.princexml.com
Index: include/libxml/xinclude.h
===================================================================
RCS file: /cvs/gnome/libxml2/include/libxml/xinclude.h,v
retrieving revision 1.13
diff -u -r1.13 xinclude.h
--- include/libxml/xinclude.h   27 Jun 2004 12:08:10 -0000      1.13
+++ include/libxml/xinclude.h   29 Sep 2006 05:46:44 -0000
@@ -95,6 +95,10 @@
                xmlXIncludeProcessFlags (xmlDocPtr doc,
                                         int flags);
 XMLPUBFUN int XMLCALL  
+               xmlXIncludeProcessFlagsData(xmlDocPtr doc,
+                                        int flags,
+                                        void *data);
+XMLPUBFUN int XMLCALL  
                xmlXIncludeProcessTree  (xmlNodePtr tree);
 XMLPUBFUN int XMLCALL  
                xmlXIncludeProcessTreeFlags(xmlNodePtr tree,
Index: xinclude.c
===================================================================
RCS file: /cvs/gnome/libxml2/xinclude.c,v
retrieving revision 1.84
diff -u -r1.84 xinclude.c
--- xinclude.c  6 Jun 2006 08:21:41 -0000       1.84
+++ xinclude.c  29 Sep 2006 05:46:45 -0000
@@ -82,6 +82,8 @@
     int                legacy; /* using XINCLUDE_OLD_NS */
     int            parseFlags; /* the flags used for parsing XML documents */
     xmlChar *           base; /* the current xml:base */
+
+    void            *_private; /* application data */
 };
 
 static int
@@ -427,6 +429,12 @@
        xmlXIncludeErrMemory(ctxt, NULL, "cannot allocate parser context");
        return(NULL);
     }
+
+    /*
+     * pass in the application data to the parser context.
+     */
+    pctxt->_private = ctxt->_private;
+    
     /*
      * try to ensure that new documents included are actually
      * built with the same dictionary as the including document.
@@ -2409,9 +2417,10 @@
 }
  
 /**
- * xmlXIncludeProcessFlags:
+ * xmlXIncludeProcessFlagsData:
  * @doc: an XML document
  * @flags: a set of xmlParserOption used for parsing XML includes
+ * @data: application data that will be passed to the parser context
  *
  * Implement the XInclude substitution on the XML document @doc
  *
@@ -2419,7 +2428,7 @@
  *    or the number of substitutions done.
  */
 int
-xmlXIncludeProcessFlags(xmlDocPtr doc, int flags) {
+xmlXIncludeProcessFlagsData(xmlDocPtr doc, int flags, void *data) {
     xmlXIncludeCtxtPtr ctxt;
     xmlNodePtr tree;
     int ret = 0;
@@ -2432,6 +2441,7 @@
     ctxt = xmlXIncludeNewContext(doc);
     if (ctxt == NULL)
        return(-1);
+    ctxt->_private = data;
     ctxt->base = xmlStrdup((xmlChar *)doc->URL);
     xmlXIncludeSetFlags(ctxt, flags);
     ret = xmlXIncludeDoProcess(ctxt, doc, tree);
@@ -2440,6 +2450,21 @@
 
     xmlXIncludeFreeContext(ctxt);
     return(ret);
+}
+
+/**
+ * xmlXIncludeProcessFlags:
+ * @doc: an XML document
+ * @flags: a set of xmlParserOption used for parsing XML includes
+ *
+ * Implement the XInclude substitution on the XML document @doc
+ *
+ * Returns 0 if no substitution were done, -1 if some processing failed
+ *    or the number of substitutions done.
+ */
+int
+xmlXIncludeProcessFlags(xmlDocPtr doc, int flags) {
+    return xmlXIncludeProcessFlagsData(doc, flags, NULL);
 }
 
 /**


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]