From 2bb89090d16cfcc42bb0015de9532094e1e57936 Mon Sep 17 00:00:00 2001
From: Daniel Veillard
Mailing-list archive: http://xmlsoft.org/messages/
-Version: $Revision: 1.1 $
+Version: $Revision: 1.2 $
Table of Content:
The module xmlIO.h
-provides the interfaces to the libxml I/O system. This consists of 3 main
+provides the interfaces to the libxml I/O system. This consists of 4 main
parts:
xmlGetExternalEntityLoader()
and
+ xmlSetExternalEntityLoader()
. Check the
+ example.The general mechanism used when loading http://rpmfind.net/xml.html for +
The general mechanism used when loading http://rpmfind.net/xml.html for example in the HTML parser is the following:
xmlNewInputFromFile()
with
+ the parsing context and the URI string.An Output handler xmlOutputBuffer
is completely similar to an
Input one except the callbacks are write() and close().
The entity loader resolves requests for new entities and create inputs for +the parser. Creating an input from a filename or an URI string is done through +the xmlNewInputFromFile() routine. The default entity loader do not handle +the PUBLIC identifier associated with an entity (if any). So it just calls +xmlNewInputFromFile() with the SYSTEM identifier (which is mandatory in +XML).
+ +If you want to hook up a catalog mechanism then you simply need to override +the default entity loader, here is an example:
+#include <libxml/xmlIO.h> + +xmlExternalEntityLoader defaultLoader = NULL; + +xmlParserInputPtr +xmlMyExternalEntityLoader(const char *URL, const char *ID, + xmlParserCtxtPtr ctxt) { + xmlParserInputPtr ret; + const char *fileID = NULL; + /* lookup for the fileID depending on ID */ + + ret = xmlNewInputFromFile(ctxt, fileID); + if (ret != NULL) + return(ret); + if (defaultLoader != NULL) + ret = defaultLoader(URL, ID, ctxt); + return(ret); +} + +int main(..) { + ... + + /* + * Install our own entity loader + */ + defaultLoader = xmlGetExternalEntityLoader(); + xmlSetExternalEntityLoader(xmlMyExternalEntityLoader); + + ... +}+
This example come from a
@@ -123,6 +175,8 @@ xmlOutputBufferCreateOwn(FILE *file, xmlCharEncodingHandlerPtr encoder) {
ret->closecallback = NULL; /* No close callback */
}
return(ret);
+
+
}
$Id: xmlio.html,v 1.1 2000/08/31 13:50:12 veillard Exp $
+$Id: xmlio.html,v 1.2 2000/08/31 14:19:54 veillard Exp $