Commit 2bb89090 authored by Daniel Veillard's avatar Daniel Veillard
Browse files

Added doc on the xmlExternalEntityLoaders and example for catalogs, Daniel

parent a7ad4522
Thu Aug 31 16:55:55 CEST 2000 Daniel Veillard <>
* doc/xmlio.html: added doc and example for entity loader
Thu Aug 31 14:59:28 CEST 2000 Daniel Veillard <>
* doc/xmlio.html doc/xml.html: added a doc on the I/O mechanism
......@@ -18,7 +18,7 @@ href=""></a></p>
<p>Mailing-list archive: <a
<p>Version: $Revision: 1.1 $</p>
<p>Version: $Revision: 1.2 $</p>
<p>Table of Content:</p>
......@@ -26,6 +26,7 @@ href=""></a></p>
<li><a href="#basic">The basic buffer type</a></li>
<li><a href="#Input">Input I/O handlers</a></li>
<li><a href="#Output">Output I/O handlers</a></li>
<li><a href="#entities">The entities loader</a></li>
<li><a href="#Example">Example of customized I/O</a></li>
......@@ -33,9 +34,16 @@ href=""></a></p>
<p>The module <code><a
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
<li>Entities loader, this is a routine which tries to fetch the entities
(files) based on their PUBLIC and SYSTEM identifiers. The default loader
don't look at the public identifier since libxml do not maintain a
catalog. You can redefine you own entity loader by using
<code>xmlGetExternalEntityLoader()</code> and
<code>xmlSetExternalEntityLoader()</code>. <a href="#entities">Check the
<li>Input I/O buffers which are a commodity structure used by the parser(s)
input layer to handle fetching the informations to feed the parser. This
provides buffering and is also a placeholder where the encoding convertors
......@@ -49,12 +57,14 @@ parts:</p>
<p> The general mechanism used when loading for
<p>The general mechanism used when loading for
example in the HTML parser is the following:</p>
<li>The default entity loader calls <code>xmlNewInputFromFile()</code> with
the parsing context and the URI string.</li>
<li>the URI string is checked against the existing registered handlers using
their match() callback function, if the HTTP module was compiled in, it is
registered and its macth() function will succeed</li>
registered and its match() function will succeeds</li>
<li>the open() function of the handler is called and if successful will
return an I/O Input buffer</li>
<li>the parser will the start reading from this buffer and progressively
......@@ -98,6 +108,48 @@ needed.</p>
<p>An Output handler <code>xmlOutputBuffer</code> is completely similar to an
Input one except the callbacks are write() and close().</p>
<h2><a name="entities">The entities loader</a></h2>
<p>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
<p>If you want to hook up a catalog mechanism then you simply need to override
the default entity loader, here is an example:</p>
<pre>#include &lt;libxml/xmlIO.h&gt;
xmlExternalEntityLoader defaultLoader = NULL;
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)
if (defaultLoader != NULL)
ret = defaultLoader(URL, ID, ctxt);
int main(..) {
* Install our own entity loader
defaultLoader = xmlGetExternalEntityLoader();
<h2><a name="Example">Example of customized I/O</a></h2>
<p>This example come from <a href="">a
......@@ -123,6 +175,8 @@ xmlOutputBufferCreateOwn(FILE *file, xmlCharEncodingHandlerPtr encoder) {
        ret-&gt;closecallback = NULL; /* No close callback */
    return(ret); <br>
} </pre>
<li>And then use it to save the document:
......@@ -142,6 +196,6 @@ res = xmlSaveFileTo(output, doc, NULL);
<p><a href="">Daniel Veillard</a></p>
<p>$Id: xmlio.html,v 1.1 2000/08/31 13:50:12 veillard Exp $</p>
<p>$Id: xmlio.html,v 1.2 2000/08/31 14:19:54 veillard Exp $</p>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment