Daniel Veillard | 43d3f61 | 2001-11-10 11:57:23 +0000 | [diff] [blame] | 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd"> |
Daniel Veillard | 9698445 | 2000-08-31 13:50:12 +0000 | [diff] [blame] | 2 | <html> |
| 3 | <head> |
Daniel Veillard | 7216cfd | 2002-11-08 15:10:00 +0000 | [diff] [blame] | 4 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> |
Daniel Veillard | c332dab | 2002-03-29 14:08:27 +0000 | [diff] [blame] | 5 | <link rel="SHORTCUT ICON" href="/favicon.ico"> |
Daniel Veillard | b8cfbd1 | 2001-10-25 10:53:28 +0000 | [diff] [blame] | 6 | <style type="text/css"><!-- |
Daniel Veillard | 373a475 | 2002-02-21 14:46:29 +0000 | [diff] [blame] | 7 | TD {font-family: Verdana,Arial,Helvetica} |
| 8 | BODY {font-family: Verdana,Arial,Helvetica; margin-top: 2em; margin-left: 0em; margin-right: 0em} |
| 9 | H1 {font-family: Verdana,Arial,Helvetica} |
| 10 | H2 {font-family: Verdana,Arial,Helvetica} |
| 11 | H3 {font-family: Verdana,Arial,Helvetica} |
Daniel Veillard | b8cfbd1 | 2001-10-25 10:53:28 +0000 | [diff] [blame] | 12 | A:link, A:visited, A:active { text-decoration: underline } |
| 13 | --></style> |
| 14 | <title>I/O Interfaces</title> |
Daniel Veillard | 9698445 | 2000-08-31 13:50:12 +0000 | [diff] [blame] | 15 | </head> |
Daniel Veillard | b8cfbd1 | 2001-10-25 10:53:28 +0000 | [diff] [blame] | 16 | <body bgcolor="#8b7765" text="#000000" link="#000000" vlink="#000000"> |
| 17 | <table border="0" width="100%" cellpadding="5" cellspacing="0" align="center"><tr> |
| 18 | <td width="180"> |
Daniel Veillard | 8f40f1e | 2002-08-28 21:18:45 +0000 | [diff] [blame] | 19 | <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> |
Daniel Veillard | b8cfbd1 | 2001-10-25 10:53:28 +0000 | [diff] [blame] | 20 | </td> |
| 21 | <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"> |
| 22 | <h1>The XML C library for Gnome</h1> |
| 23 | <h2>I/O Interfaces</h2> |
| 24 | </td></tr></table></td></tr></table></td> |
| 25 | </tr></table> |
| 26 | <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> |
| 27 | <td valign="top" width="200" bgcolor="#8b7765"><table border="0" cellspacing="0" cellpadding="1" width="100%" bgcolor="#000000"><tr><td> |
| 28 | <table width="100%" border="0" cellspacing="1" cellpadding="3"> |
| 29 | <tr><td colspan="1" bgcolor="#eecfa1" align="center"><center><b>Main Menu</b></center></td></tr> |
Daniel Veillard | 4a603e4 | 2003-01-11 14:18:53 +0000 | [diff] [blame] | 30 | <tr><td bgcolor="#fffacd"> |
| 31 | <form action="search.php" enctype="application/x-www-form-urlencoded" method="GET"> |
| 32 | <input name="query" type="TEXT" size="20" value=""><input name="submit" type="submit" value="Search ..."> |
| 33 | </form> |
| 34 | <ul> |
Daniel Veillard | b8cfbd1 | 2001-10-25 10:53:28 +0000 | [diff] [blame] | 35 | <li><a href="index.html">Home</a></li> |
| 36 | <li><a href="intro.html">Introduction</a></li> |
| 37 | <li><a href="FAQ.html">FAQ</a></li> |
| 38 | <li><a href="docs.html">Documentation</a></li> |
| 39 | <li><a href="bugs.html">Reporting bugs and getting help</a></li> |
| 40 | <li><a href="help.html">How to help</a></li> |
| 41 | <li><a href="downloads.html">Downloads</a></li> |
| 42 | <li><a href="news.html">News</a></li> |
Daniel Veillard | 7b602b4 | 2002-01-08 13:26:00 +0000 | [diff] [blame] | 43 | <li><a href="XMLinfo.html">XML</a></li> |
Daniel Veillard | b8cfbd1 | 2001-10-25 10:53:28 +0000 | [diff] [blame] | 44 | <li><a href="XSLT.html">XSLT</a></li> |
Daniel Veillard | 6dbcaf8 | 2002-02-20 14:37:47 +0000 | [diff] [blame] | 45 | <li><a href="python.html">Python and bindings</a></li> |
Daniel Veillard | b8cfbd1 | 2001-10-25 10:53:28 +0000 | [diff] [blame] | 46 | <li><a href="architecture.html">libxml architecture</a></li> |
| 47 | <li><a href="tree.html">The tree output</a></li> |
| 48 | <li><a href="interface.html">The SAX interface</a></li> |
| 49 | <li><a href="xmldtd.html">Validation & DTDs</a></li> |
| 50 | <li><a href="xmlmem.html">Memory Management</a></li> |
| 51 | <li><a href="encoding.html">Encodings support</a></li> |
| 52 | <li><a href="xmlio.html">I/O Interfaces</a></li> |
| 53 | <li><a href="catalog.html">Catalog support</a></li> |
| 54 | <li><a href="library.html">The parser interfaces</a></li> |
| 55 | <li><a href="entities.html">Entities or no entities</a></li> |
| 56 | <li><a href="namespaces.html">Namespaces</a></li> |
| 57 | <li><a href="upgrade.html">Upgrading 1.x code</a></li> |
Daniel Veillard | 52dcab3 | 2001-10-30 12:51:17 +0000 | [diff] [blame] | 58 | <li><a href="threads.html">Thread safety</a></li> |
Daniel Veillard | b8cfbd1 | 2001-10-25 10:53:28 +0000 | [diff] [blame] | 59 | <li><a href="DOM.html">DOM Principles</a></li> |
| 60 | <li><a href="example.html">A real example</a></li> |
| 61 | <li><a href="contribs.html">Contributions</a></li> |
Daniel Veillard | 7b4b2f9 | 2003-01-06 13:11:20 +0000 | [diff] [blame] | 62 | <li><a href="xmlreader.html">The Reader Interface</a></li> |
Daniel Veillard | fc59c09 | 2002-06-05 14:48:26 +0000 | [diff] [blame] | 63 | <li><a href="tutorial/index.html">Tutorial</a></li> |
Daniel Veillard | 7b4b2f9 | 2003-01-06 13:11:20 +0000 | [diff] [blame] | 64 | <li><a href="guidelines.html">XML Guidelines</a></li> |
Daniel Veillard | b8cfbd1 | 2001-10-25 10:53:28 +0000 | [diff] [blame] | 65 | <li> |
| 66 | <a href="xml.html">flat page</a>, <a href="site.xsl">stylesheet</a> |
| 67 | </li> |
Daniel Veillard | 5ede35e | 2002-10-01 11:37:35 +0000 | [diff] [blame] | 68 | </ul> |
| 69 | </td></tr> |
Daniel Veillard | 3bf65be | 2002-01-23 12:36:34 +0000 | [diff] [blame] | 70 | </table> |
| 71 | <table width="100%" border="0" cellspacing="1" cellpadding="3"> |
Daniel Veillard | b8cfbd1 | 2001-10-25 10:53:28 +0000 | [diff] [blame] | 72 | <tr><td colspan="1" bgcolor="#eecfa1" align="center"><center><b>Related links</b></center></td></tr> |
Daniel Veillard | 8acca11 | 2002-01-21 09:52:27 +0000 | [diff] [blame] | 73 | <tr><td bgcolor="#fffacd"><ul> |
Daniel Veillard | b8cfbd1 | 2001-10-25 10:53:28 +0000 | [diff] [blame] | 74 | <li><a href="http://mail.gnome.org/archives/xml/">Mail archive</a></li> |
| 75 | <li><a href="http://xmlsoft.org/XSLT/">XSLT libxslt</a></li> |
Daniel Veillard | 4a85920 | 2002-01-08 11:49:22 +0000 | [diff] [blame] | 76 | <li><a href="http://phd.cs.unibo.it/gdome2/">DOM gdome2</a></li> |
Daniel Veillard | 2d347fa | 2002-03-17 10:34:11 +0000 | [diff] [blame] | 77 | <li><a href="http://www.aleksey.com/xmlsec/">XML-DSig xmlsec</a></li> |
Daniel Veillard | b8cfbd1 | 2001-10-25 10:53:28 +0000 | [diff] [blame] | 78 | <li><a href="ftp://xmlsoft.org/">FTP</a></li> |
Daniel Veillard | c84f8b5 | 2002-12-19 22:12:47 +0000 | [diff] [blame] | 79 | <li><a href="http://www.zlatkovic.com/projects/libxml/">Windows binaries</a></li> |
Daniel Veillard | db9dfd9 | 2001-11-26 17:25:02 +0000 | [diff] [blame] | 80 | <li><a href="http://garypennington.net/libxml2/">Solaris binaries</a></li> |
Daniel Veillard | cb7543b | 2002-09-09 10:54:06 +0000 | [diff] [blame] | 81 | <li><a href="http://www.zveno.com/open_source/libxml2xslt.html">MacOsX binaries</a></li> |
Daniel Veillard | e6d8e20 | 2002-05-02 06:11:10 +0000 | [diff] [blame] | 82 | <li><a href="http://sourceforge.net/projects/libxml2-pas/">Pascal bindings</a></li> |
Daniel Veillard | 2d347fa | 2002-03-17 10:34:11 +0000 | [diff] [blame] | 83 | <li><a href="http://bugzilla.gnome.org/buglist.cgi?product=libxml&product=libxml2">Bug Tracker</a></li> |
Daniel Veillard | b8cfbd1 | 2001-10-25 10:53:28 +0000 | [diff] [blame] | 84 | </ul></td></tr> |
| 85 | </table> |
Daniel Veillard | 4a603e4 | 2003-01-11 14:18:53 +0000 | [diff] [blame] | 86 | <table width="100%" border="0" cellspacing="1" cellpadding="3"> |
| 87 | <tr><td colspan="1" bgcolor="#eecfa1" align="center"><center><b>API Indexes</b></center></td></tr> |
| 88 | <tr><td bgcolor="#fffacd"><ul> |
| 89 | <li><a href="APIchunk0.html">Alphabetic</a></li> |
| 90 | <li><a href="APIconstructors.html">Constructors</a></li> |
| 91 | <li><a href="APIfunctions.html">Functions/Types</a></li> |
| 92 | <li><a href="APIfiles.html">Modules</a></li> |
| 93 | <li><a href="APIsymbols.html">Symbols</a></li> |
| 94 | </ul></td></tr> |
| 95 | </table> |
Daniel Veillard | b8cfbd1 | 2001-10-25 10:53:28 +0000 | [diff] [blame] | 96 | </td></tr></table></td> |
| 97 | <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"> |
Daniel Veillard | 9698445 | 2000-08-31 13:50:12 +0000 | [diff] [blame] | 98 | <p>Table of Content:</p> |
| 99 | <ol> |
Daniel Veillard | b8cfbd1 | 2001-10-25 10:53:28 +0000 | [diff] [blame] | 100 | <li><a href="#General1">General overview</a></li> |
Daniel Veillard | 0b28e88 | 2002-07-24 23:47:05 +0000 | [diff] [blame] | 101 | <li><a href="#basic">The basic buffer type</a></li> |
| 102 | <li><a href="#Input">Input I/O handlers</a></li> |
| 103 | <li><a href="#Output">Output I/O handlers</a></li> |
| 104 | <li><a href="#entities">The entities loader</a></li> |
| 105 | <li><a href="#Example2">Example of customized I/O</a></li> |
Daniel Veillard | 9698445 | 2000-08-31 13:50:12 +0000 | [diff] [blame] | 106 | </ol> |
Daniel Veillard | b8cfbd1 | 2001-10-25 10:53:28 +0000 | [diff] [blame] | 107 | <h3><a name="General1">General overview</a></h3> |
| 108 | <p>The module <code><a href="http://xmlsoft.org/html/libxml-xmlio.html">xmlIO.h</a></code> provides |
| 109 | the interfaces to the libxml I/O system. This consists of 4 main parts:</p> |
Daniel Veillard | 9698445 | 2000-08-31 13:50:12 +0000 | [diff] [blame] | 110 | <ul> |
Daniel Veillard | b8cfbd1 | 2001-10-25 10:53:28 +0000 | [diff] [blame] | 111 | <li>Entities loader, this is a routine which tries to fetch the entities |
Daniel Veillard | 2bb8909 | 2000-08-31 14:57:50 +0000 | [diff] [blame] | 112 | (files) based on their PUBLIC and SYSTEM identifiers. The default loader |
| 113 | don't look at the public identifier since libxml do not maintain a |
| 114 | catalog. You can redefine you own entity loader by using |
| 115 | <code>xmlGetExternalEntityLoader()</code> and |
Daniel Veillard | 9c46682 | 2001-10-25 12:03:39 +0000 | [diff] [blame] | 116 | <code>xmlSetExternalEntityLoader()</code>. <a href="#entities">Check the |
| 117 | example</a>.</li> |
Daniel Veillard | 0b28e88 | 2002-07-24 23:47:05 +0000 | [diff] [blame] | 118 | <li>Input I/O buffers which are a commodity structure used by the parser(s) |
Daniel Veillard | 9698445 | 2000-08-31 13:50:12 +0000 | [diff] [blame] | 119 | input layer to handle fetching the informations to feed the parser. This |
Daniel Veillard | b8cfbd1 | 2001-10-25 10:53:28 +0000 | [diff] [blame] | 120 | provides buffering and is also a placeholder where the encoding |
Daniel Veillard | 63d8314 | 2002-05-20 06:51:05 +0000 | [diff] [blame] | 121 | converters to UTF8 are piggy-backed.</li> |
Daniel Veillard | 0b28e88 | 2002-07-24 23:47:05 +0000 | [diff] [blame] | 122 | <li>Output I/O buffers are similar to the Input ones and fulfill similar |
Daniel Veillard | 9698445 | 2000-08-31 13:50:12 +0000 | [diff] [blame] | 123 | task but when generating a serialization from a tree.</li> |
Daniel Veillard | 0b28e88 | 2002-07-24 23:47:05 +0000 | [diff] [blame] | 124 | <li>A mechanism to register sets of I/O callbacks and associate them with |
Daniel Veillard | 9698445 | 2000-08-31 13:50:12 +0000 | [diff] [blame] | 125 | specific naming schemes like the protocol part of the URIs. |
| 126 | <p>This affect the default I/O operations and allows to use specific I/O |
| 127 | handlers for certain names.</p> |
Daniel Veillard | 0b28e88 | 2002-07-24 23:47:05 +0000 | [diff] [blame] | 128 | </li> |
Daniel Veillard | 9698445 | 2000-08-31 13:50:12 +0000 | [diff] [blame] | 129 | </ul> |
Daniel Veillard | 2bb8909 | 2000-08-31 14:57:50 +0000 | [diff] [blame] | 130 | <p>The general mechanism used when loading http://rpmfind.net/xml.html for |
Daniel Veillard | 9698445 | 2000-08-31 13:50:12 +0000 | [diff] [blame] | 131 | example in the HTML parser is the following:</p> |
| 132 | <ol> |
Daniel Veillard | b8cfbd1 | 2001-10-25 10:53:28 +0000 | [diff] [blame] | 133 | <li>The default entity loader calls <code>xmlNewInputFromFile()</code> with |
Daniel Veillard | 2bb8909 | 2000-08-31 14:57:50 +0000 | [diff] [blame] | 134 | the parsing context and the URI string.</li> |
Daniel Veillard | 0b28e88 | 2002-07-24 23:47:05 +0000 | [diff] [blame] | 135 | <li>the URI string is checked against the existing registered handlers |
Daniel Veillard | b8cfbd1 | 2001-10-25 10:53:28 +0000 | [diff] [blame] | 136 | using their match() callback function, if the HTTP module was compiled |
| 137 | in, it is registered and its match() function will succeeds</li> |
Daniel Veillard | 0b28e88 | 2002-07-24 23:47:05 +0000 | [diff] [blame] | 138 | <li>the open() function of the handler is called and if successful will |
Daniel Veillard | 9698445 | 2000-08-31 13:50:12 +0000 | [diff] [blame] | 139 | return an I/O Input buffer</li> |
Daniel Veillard | 0b28e88 | 2002-07-24 23:47:05 +0000 | [diff] [blame] | 140 | <li>the parser will the start reading from this buffer and progressively |
Daniel Veillard | 9698445 | 2000-08-31 13:50:12 +0000 | [diff] [blame] | 141 | fetch information from the resource, calling the read() function of the |
| 142 | handler until the resource is exhausted</li> |
Daniel Veillard | 0b28e88 | 2002-07-24 23:47:05 +0000 | [diff] [blame] | 143 | <li>if an encoding change is detected it will be installed on the input |
Daniel Veillard | 9698445 | 2000-08-31 13:50:12 +0000 | [diff] [blame] | 144 | buffer, providing buffering and efficient use of the conversion |
| 145 | routines</li> |
Daniel Veillard | 0b28e88 | 2002-07-24 23:47:05 +0000 | [diff] [blame] | 146 | <li>once the parser has finished, the close() function of the handler is |
Daniel Veillard | 63d8314 | 2002-05-20 06:51:05 +0000 | [diff] [blame] | 147 | called once and the Input buffer and associated resources are |
Daniel Veillard | 9698445 | 2000-08-31 13:50:12 +0000 | [diff] [blame] | 148 | deallocated.</li> |
| 149 | </ol> |
Daniel Veillard | 9698445 | 2000-08-31 13:50:12 +0000 | [diff] [blame] | 150 | <p>The user defined callbacks are checked first to allow overriding of the |
| 151 | default libxml I/O routines.</p> |
Daniel Veillard | b8cfbd1 | 2001-10-25 10:53:28 +0000 | [diff] [blame] | 152 | <h3><a name="basic">The basic buffer type</a></h3> |
Daniel Veillard | 9698445 | 2000-08-31 13:50:12 +0000 | [diff] [blame] | 153 | <p>All the buffer manipulation handling is done using the |
Daniel Veillard | 0b28e88 | 2002-07-24 23:47:05 +0000 | [diff] [blame] | 154 | <code>xmlBuffer</code> type define in <code><a href="http://xmlsoft.org/html/libxml-tree.html">tree.h</a> </code>which is a |
Daniel Veillard | b8cfbd1 | 2001-10-25 10:53:28 +0000 | [diff] [blame] | 155 | resizable memory buffer. The buffer allocation strategy can be selected to be |
| 156 | either best-fit or use an exponential doubling one (CPU vs. memory use |
Daniel Veillard | 63d8314 | 2002-05-20 06:51:05 +0000 | [diff] [blame] | 157 | trade-off). The values are <code>XML_BUFFER_ALLOC_EXACT</code> and |
Daniel Veillard | 9698445 | 2000-08-31 13:50:12 +0000 | [diff] [blame] | 158 | <code>XML_BUFFER_ALLOC_DOUBLEIT</code>, and can be set individually or on a |
| 159 | system wide basis using <code>xmlBufferSetAllocationScheme()</code>. A number |
| 160 | of functions allows to manipulate buffers with names starting with the |
| 161 | <code>xmlBuffer...</code> prefix.</p> |
Daniel Veillard | b8cfbd1 | 2001-10-25 10:53:28 +0000 | [diff] [blame] | 162 | <h3><a name="Input">Input I/O handlers</a></h3> |
Daniel Veillard | 9698445 | 2000-08-31 13:50:12 +0000 | [diff] [blame] | 163 | <p>An Input I/O handler is a simple structure |
| 164 | <code>xmlParserInputBuffer</code> containing a context associated to the |
| 165 | resource (file descriptor, or pointer to a protocol handler), the read() and |
| 166 | close() callbacks to use and an xmlBuffer. And extra xmlBuffer and a charset |
| 167 | encoding handler are also present to support charset conversion when |
| 168 | needed.</p> |
Daniel Veillard | b8cfbd1 | 2001-10-25 10:53:28 +0000 | [diff] [blame] | 169 | <h3><a name="Output">Output I/O handlers</a></h3> |
Daniel Veillard | 9698445 | 2000-08-31 13:50:12 +0000 | [diff] [blame] | 170 | <p>An Output handler <code>xmlOutputBuffer</code> is completely similar to an |
| 171 | Input one except the callbacks are write() and close().</p> |
Daniel Veillard | b8cfbd1 | 2001-10-25 10:53:28 +0000 | [diff] [blame] | 172 | <h3><a name="entities">The entities loader</a></h3> |
Daniel Veillard | 2bb8909 | 2000-08-31 14:57:50 +0000 | [diff] [blame] | 173 | <p>The entity loader resolves requests for new entities and create inputs for |
Daniel Veillard | b8cfbd1 | 2001-10-25 10:53:28 +0000 | [diff] [blame] | 174 | the parser. Creating an input from a filename or an URI string is done |
| 175 | through the xmlNewInputFromFile() routine. The default entity loader do not |
| 176 | handle the PUBLIC identifier associated with an entity (if any). So it just |
| 177 | calls xmlNewInputFromFile() with the SYSTEM identifier (which is mandatory in |
Daniel Veillard | 2bb8909 | 2000-08-31 14:57:50 +0000 | [diff] [blame] | 178 | XML).</p> |
Daniel Veillard | b8cfbd1 | 2001-10-25 10:53:28 +0000 | [diff] [blame] | 179 | <p>If you want to hook up a catalog mechanism then you simply need to |
| 180 | override the default entity loader, here is an example:</p> |
Daniel Veillard | 2bb8909 | 2000-08-31 14:57:50 +0000 | [diff] [blame] | 181 | <pre>#include <libxml/xmlIO.h> |
| 182 | |
| 183 | xmlExternalEntityLoader defaultLoader = NULL; |
| 184 | |
| 185 | xmlParserInputPtr |
| 186 | xmlMyExternalEntityLoader(const char *URL, const char *ID, |
| 187 | xmlParserCtxtPtr ctxt) { |
| 188 | xmlParserInputPtr ret; |
| 189 | const char *fileID = NULL; |
| 190 | /* lookup for the fileID depending on ID */ |
| 191 | |
| 192 | ret = xmlNewInputFromFile(ctxt, fileID); |
| 193 | if (ret != NULL) |
| 194 | return(ret); |
| 195 | if (defaultLoader != NULL) |
| 196 | ret = defaultLoader(URL, ID, ctxt); |
| 197 | return(ret); |
| 198 | } |
| 199 | |
| 200 | int main(..) { |
| 201 | ... |
| 202 | |
| 203 | /* |
| 204 | * Install our own entity loader |
| 205 | */ |
| 206 | defaultLoader = xmlGetExternalEntityLoader(); |
| 207 | xmlSetExternalEntityLoader(xmlMyExternalEntityLoader); |
| 208 | |
| 209 | ... |
| 210 | }</pre> |
Daniel Veillard | b8cfbd1 | 2001-10-25 10:53:28 +0000 | [diff] [blame] | 211 | <h3><a name="Example2">Example of customized I/O</a></h3> |
Daniel Veillard | 9698445 | 2000-08-31 13:50:12 +0000 | [diff] [blame] | 212 | <p>This example come from <a href="http://xmlsoft.org/messages/0708.html">a |
| 213 | real use case</a>, xmlDocDump() closes the FILE * passed by the application |
Daniel Veillard | b8cfbd1 | 2001-10-25 10:53:28 +0000 | [diff] [blame] | 214 | and this was a problem. The <a href="http://xmlsoft.org/messages/0711.html">solution</a> was to redefine a |
Daniel Veillard | 9698445 | 2000-08-31 13:50:12 +0000 | [diff] [blame] | 215 | new output handler with the closing call deactivated:</p> |
| 216 | <ol> |
Daniel Veillard | c0801af | 2002-05-28 16:28:42 +0000 | [diff] [blame] | 217 | <li>First define a new I/O output allocator where the output don't close |
| 218 | the file: |
Daniel Veillard | a7ad452 | 2000-08-31 14:19:54 +0000 | [diff] [blame] | 219 | <pre>xmlOutputBufferPtr |
| 220 | xmlOutputBufferCreateOwn(FILE *file, xmlCharEncodingHandlerPtr encoder) { |
| 221 | xmlOutputBufferPtr ret; |
| 222 | |
| 223 | if (xmlOutputCallbackInitialized == 0) |
| 224 | xmlRegisterDefaultOutputCallbacks(); |
| 225 | |
| 226 | if (file == NULL) return(NULL); |
| 227 | ret = xmlAllocOutputBuffer(encoder); |
| 228 | if (ret != NULL) { |
| 229 | ret->context = file; |
| 230 | ret->writecallback = xmlFileWrite; |
| 231 | ret->closecallback = NULL; /* No close callback */ |
| 232 | } |
| 233 | return(ret); <br> |
Daniel Veillard | 1eb2424 | 2002-03-18 11:33:03 +0000 | [diff] [blame] | 234 | |
Daniel Veillard | 34ce8be | 2002-03-18 19:37:11 +0000 | [diff] [blame] | 235 | |
| 236 | |
Daniel Veillard | 1927409 | 2002-03-25 16:48:03 +0000 | [diff] [blame] | 237 | |
Daniel Veillard | b2fb8ed | 2002-04-01 09:33:12 +0000 | [diff] [blame] | 238 | |
Daniel Veillard | a8a89fe | 2002-04-12 21:03:34 +0000 | [diff] [blame] | 239 | |
Daniel Veillard | c397534 | 2002-04-15 18:54:52 +0000 | [diff] [blame] | 240 | |
Daniel Veillard | 0bfbb42 | 2002-04-26 09:21:45 +0000 | [diff] [blame] | 241 | |
Daniel Veillard | 93d3a47 | 2002-04-26 14:04:55 +0000 | [diff] [blame] | 242 | |
Daniel Veillard | cf27f7c | 2002-04-30 07:12:39 +0000 | [diff] [blame] | 243 | |
Daniel Veillard | e6d8e20 | 2002-05-02 06:11:10 +0000 | [diff] [blame] | 244 | |
Daniel Veillard | 9b6fd30 | 2002-05-13 12:06:47 +0000 | [diff] [blame] | 245 | |
Daniel Veillard | c0801af | 2002-05-28 16:28:42 +0000 | [diff] [blame] | 246 | |
Daniel Veillard | 2147367 | 2002-06-17 07:29:22 +0000 | [diff] [blame] | 247 | |
Daniel Veillard | 782afda | 2002-07-08 15:12:49 +0000 | [diff] [blame] | 248 | |
Daniel Veillard | 42766c0 | 2002-08-22 20:52:17 +0000 | [diff] [blame] | 249 | |
Daniel Veillard | e166254 | 2002-08-28 11:50:59 +0000 | [diff] [blame] | 250 | |
Daniel Veillard | e16b574 | 2002-09-26 17:50:03 +0000 | [diff] [blame] | 251 | |
Daniel Veillard | 321be0c | 2002-10-08 21:26:42 +0000 | [diff] [blame] | 252 | |
Daniel Veillard | e645e8c | 2002-10-22 17:35:37 +0000 | [diff] [blame] | 253 | |
Daniel Veillard | dad3f68 | 2002-11-17 16:47:27 +0000 | [diff] [blame] | 254 | |
Daniel Veillard | c14401e | 2002-11-20 14:28:17 +0000 | [diff] [blame] | 255 | |
Daniel Veillard | f9c4cad | 2002-11-22 15:57:07 +0000 | [diff] [blame] | 256 | |
Daniel Veillard | 9b4bb4d | 2002-12-11 19:28:47 +0000 | [diff] [blame] | 257 | |
Daniel Veillard | c1eed32 | 2002-12-12 11:01:32 +0000 | [diff] [blame] | 258 | |
Daniel Veillard | 7ef0fcb | 2002-12-14 10:38:55 +0000 | [diff] [blame] | 259 | |
Daniel Veillard | 7b4b2f9 | 2003-01-06 13:11:20 +0000 | [diff] [blame] | 260 | |
| 261 | |
Daniel Veillard | e2830f1 | 2003-01-08 17:47:49 +0000 | [diff] [blame] | 262 | |
Daniel Veillard | 98d071d | 2003-01-10 09:22:44 +0000 | [diff] [blame] | 263 | |
| 264 | |
Daniel Veillard | 831e8fd | 2003-01-25 11:45:34 +0000 | [diff] [blame] | 265 | |
Daniel Veillard | 9698445 | 2000-08-31 13:50:12 +0000 | [diff] [blame] | 266 | } </pre> |
Daniel Veillard | 0b28e88 | 2002-07-24 23:47:05 +0000 | [diff] [blame] | 267 | </li> |
| 268 | <li>And then use it to save the document: |
Daniel Veillard | 9698445 | 2000-08-31 13:50:12 +0000 | [diff] [blame] | 269 | <pre>FILE *f; |
Daniel Veillard | a7ad452 | 2000-08-31 14:19:54 +0000 | [diff] [blame] | 270 | xmlOutputBufferPtr output; |
| 271 | xmlDocPtr doc; |
Daniel Veillard | 9698445 | 2000-08-31 13:50:12 +0000 | [diff] [blame] | 272 | int res; |
Daniel Veillard | a7ad452 | 2000-08-31 14:19:54 +0000 | [diff] [blame] | 273 | |
Daniel Veillard | 9698445 | 2000-08-31 13:50:12 +0000 | [diff] [blame] | 274 | f = ... |
| 275 | doc = .... |
Daniel Veillard | 9698445 | 2000-08-31 13:50:12 +0000 | [diff] [blame] | 276 | |
Daniel Veillard | a7ad452 | 2000-08-31 14:19:54 +0000 | [diff] [blame] | 277 | output = xmlOutputBufferCreateOwn(f, NULL); |
| 278 | res = xmlSaveFileTo(output, doc, NULL); |
Daniel Veillard | 9698445 | 2000-08-31 13:50:12 +0000 | [diff] [blame] | 279 | </pre> |
Daniel Veillard | 0b28e88 | 2002-07-24 23:47:05 +0000 | [diff] [blame] | 280 | </li> |
Daniel Veillard | 9698445 | 2000-08-31 13:50:12 +0000 | [diff] [blame] | 281 | </ol> |
Daniel Veillard | 3f4c40f | 2002-02-13 09:19:28 +0000 | [diff] [blame] | 282 | <p><a href="bugs.html">Daniel Veillard</a></p> |
Daniel Veillard | b8cfbd1 | 2001-10-25 10:53:28 +0000 | [diff] [blame] | 283 | </td></tr></table></td></tr></table></td></tr></table></td> |
| 284 | </tr></table></td></tr></table> |
Daniel Veillard | 9698445 | 2000-08-31 13:50:12 +0000 | [diff] [blame] | 285 | </body> |
| 286 | </html> |