1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>xmlsave: the XML document serializer</title> 5<meta name="generator" content="Libxml2 devhelp stylesheet"> 6<link rel="start" href="index.html" title="libxml2 Reference Manual"> 7<link rel="up" href="general.html" title="API"> 8<link rel="stylesheet" href="style.css" type="text/css"> 9<link rel="chapter" href="general.html" title="API"> 10</head> 11<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> 12<table class="navigation" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2"><tr valign="middle"> 13<td><a accesskey="p" href="libxml2-xmlregexp.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td> 14<td><a accesskey="u" href="general.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td> 15<td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td> 16<td><a accesskey="n" href="libxml2-xmlschemas.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td> 17<th width="100%" align="center">libxml2 Reference Manual</th> 18</tr></table> 19<h2><span class="refentrytitle">xmlsave</span></h2> 20<p>xmlsave - the XML document serializer</p> 21<p>API to save document or subtree of document </p> 22<p>Author(s): Daniel Veillard </p> 23<div class="refsynopsisdiv"> 24<h2>Synopsis</h2> 25<pre class="synopsis">typedef struct _xmlSaveCtxt <a href="#xmlSaveCtxt">xmlSaveCtxt</a>; 26typedef <a href="libxml2-xmlsave.html#xmlSaveCtxt">xmlSaveCtxt</a> * <a href="#xmlSaveCtxtPtr">xmlSaveCtxtPtr</a>; 27typedef enum <a href="#xmlSaveOption">xmlSaveOption</a>; 28int <a href="#xmlSaveClose">xmlSaveClose</a> (<a href="libxml2-xmlsave.html#xmlSaveCtxtPtr">xmlSaveCtxtPtr</a> ctxt); 29long <a href="#xmlSaveDoc">xmlSaveDoc</a> (<a href="libxml2-xmlsave.html#xmlSaveCtxtPtr">xmlSaveCtxtPtr</a> ctxt, <br> <a href="libxml2-tree.html#xmlDocPtr">xmlDocPtr</a> doc); 30int <a href="#xmlSaveFlush">xmlSaveFlush</a> (<a href="libxml2-xmlsave.html#xmlSaveCtxtPtr">xmlSaveCtxtPtr</a> ctxt); 31int <a href="#xmlSaveSetAttrEscape">xmlSaveSetAttrEscape</a> (<a href="libxml2-xmlsave.html#xmlSaveCtxtPtr">xmlSaveCtxtPtr</a> ctxt, <br> <a href="libxml2-encoding.html#xmlCharEncodingOutputFunc">xmlCharEncodingOutputFunc</a> escape); 32int <a href="#xmlSaveSetEscape">xmlSaveSetEscape</a> (<a href="libxml2-xmlsave.html#xmlSaveCtxtPtr">xmlSaveCtxtPtr</a> ctxt, <br> <a href="libxml2-encoding.html#xmlCharEncodingOutputFunc">xmlCharEncodingOutputFunc</a> escape); 33<a href="libxml2-xmlsave.html#xmlSaveCtxtPtr">xmlSaveCtxtPtr</a> <a href="#xmlSaveToBuffer">xmlSaveToBuffer</a> (<a href="libxml2-tree.html#xmlBufferPtr">xmlBufferPtr</a> buffer, <br> const char * encoding, <br> int options); 34<a href="libxml2-xmlsave.html#xmlSaveCtxtPtr">xmlSaveCtxtPtr</a> <a href="#xmlSaveToFd">xmlSaveToFd</a> (int fd, <br> const char * encoding, <br> int options); 35<a href="libxml2-xmlsave.html#xmlSaveCtxtPtr">xmlSaveCtxtPtr</a> <a href="#xmlSaveToFilename">xmlSaveToFilename</a> (const char * filename, <br> const char * encoding, <br> int options); 36<a href="libxml2-xmlsave.html#xmlSaveCtxtPtr">xmlSaveCtxtPtr</a> <a href="#xmlSaveToIO">xmlSaveToIO</a> (<a href="libxml2-xmlIO.html#xmlOutputWriteCallback">xmlOutputWriteCallback</a> iowrite, <br> <a href="libxml2-xmlIO.html#xmlOutputCloseCallback">xmlOutputCloseCallback</a> ioclose, <br> void * ioctx, <br> const char * encoding, <br> int options); 37long <a href="#xmlSaveTree">xmlSaveTree</a> (<a href="libxml2-xmlsave.html#xmlSaveCtxtPtr">xmlSaveCtxtPtr</a> ctxt, <br> <a href="libxml2-tree.html#xmlNodePtr">xmlNodePtr</a> cur); 38</pre> 39</div> 40<div class="refsect1" lang="en"><h2>Description</h2></div> 41<div class="refsect1" lang="en"> 42<h2>Details</h2> 43<div class="refsect2" lang="en"> 44<div class="refsect2" lang="en"> 45<h3> 46<a name="xmlSaveCtxt">Structure </a>xmlSaveCtxt</h3> 47<pre class="programlisting">struct _xmlSaveCtxt { 48The content of this structure is not made public by the API. 49} xmlSaveCtxt; 50</pre> 51<p></p> 52</div> 53<hr> 54<div class="refsect2" lang="en"> 55<h3> 56<a name="xmlSaveCtxtPtr">Typedef </a>xmlSaveCtxtPtr</h3> 57<pre class="programlisting"><a href="libxml2-xmlsave.html#xmlSaveCtxt">xmlSaveCtxt</a> * xmlSaveCtxtPtr; 58</pre> 59<p></p> 60</div> 61<hr> 62<div class="refsect2" lang="en"> 63<h3> 64<a name="xmlSaveOption">Enum </a>xmlSaveOption</h3> 65<pre class="programlisting">enum <a href="#xmlSaveOption">xmlSaveOption</a> { 66 <a name="XML_SAVE_FORMAT">XML_SAVE_FORMAT</a> = 1 /* format save output */ 67 <a name="XML_SAVE_NO_DECL">XML_SAVE_NO_DECL</a> = 2 /* drop the xml declaration */ 68 <a name="XML_SAVE_NO_EMPTY">XML_SAVE_NO_EMPTY</a> = 4 /* no empty tags */ 69 <a name="XML_SAVE_NO_XHTML">XML_SAVE_NO_XHTML</a> = 8 /* disable XHTML1 specific rules */ 70 <a name="XML_SAVE_XHTML">XML_SAVE_XHTML</a> = 16 /* force XHTML1 specific rules */ 71 <a name="XML_SAVE_AS_XML">XML_SAVE_AS_XML</a> = 32 /* force XML serialization on HTML doc */ 72 <a name="XML_SAVE_AS_HTML">XML_SAVE_AS_HTML</a> = 64 /* force HTML serialization on XML doc */ 73 <a name="XML_SAVE_WSNONSIG">XML_SAVE_WSNONSIG</a> = 128 /* format with non-significant whitespace */ 74}; 75</pre> 76<p></p> 77</div> 78<hr> 79<div class="refsect2" lang="en"> 80<h3> 81<a name="xmlSaveClose"></a>xmlSaveClose ()</h3> 82<pre class="programlisting">int xmlSaveClose (<a href="libxml2-xmlsave.html#xmlSaveCtxtPtr">xmlSaveCtxtPtr</a> ctxt)<br> 83</pre> 84<p>Close a document saving context, i.e. make sure that all bytes have been output and free the associated data.</p> 85<div class="variablelist"><table border="0"> 86<col align="left"> 87<tbody> 88<tr> 89<td><span class="term"><i><tt>ctxt</tt></i>:</span></td> 90<td>a document saving context</td> 91</tr> 92<tr> 93<td><span class="term"><i><tt>Returns</tt></i>:</span></td> 94<td>the number of byte written or -1 in case of error.</td> 95</tr> 96</tbody> 97</table></div> 98</div> 99<hr> 100<div class="refsect2" lang="en"> 101<h3> 102<a name="xmlSaveDoc"></a>xmlSaveDoc ()</h3> 103<pre class="programlisting">long xmlSaveDoc (<a href="libxml2-xmlsave.html#xmlSaveCtxtPtr">xmlSaveCtxtPtr</a> ctxt, <br> <a href="libxml2-tree.html#xmlDocPtr">xmlDocPtr</a> doc)<br> 104</pre> 105<p>Save a full document to a saving context TODO: The function is not fully implemented yet as it does not return the byte count but 0 instead</p> 106<div class="variablelist"><table border="0"> 107<col align="left"> 108<tbody> 109<tr> 110<td><span class="term"><i><tt>ctxt</tt></i>:</span></td> 111<td>a document saving context</td> 112</tr> 113<tr> 114<td><span class="term"><i><tt>doc</tt></i>:</span></td> 115<td>a document</td> 116</tr> 117<tr> 118<td><span class="term"><i><tt>Returns</tt></i>:</span></td> 119<td>the number of byte written or -1 in case of error</td> 120</tr> 121</tbody> 122</table></div> 123</div> 124<hr> 125<div class="refsect2" lang="en"> 126<h3> 127<a name="xmlSaveFlush"></a>xmlSaveFlush ()</h3> 128<pre class="programlisting">int xmlSaveFlush (<a href="libxml2-xmlsave.html#xmlSaveCtxtPtr">xmlSaveCtxtPtr</a> ctxt)<br> 129</pre> 130<p>Flush a document saving context, i.e. make sure that all bytes have been output.</p> 131<div class="variablelist"><table border="0"> 132<col align="left"> 133<tbody> 134<tr> 135<td><span class="term"><i><tt>ctxt</tt></i>:</span></td> 136<td>a document saving context</td> 137</tr> 138<tr> 139<td><span class="term"><i><tt>Returns</tt></i>:</span></td> 140<td>the number of byte written or -1 in case of error.</td> 141</tr> 142</tbody> 143</table></div> 144</div> 145<hr> 146<div class="refsect2" lang="en"> 147<h3> 148<a name="xmlSaveSetAttrEscape"></a>xmlSaveSetAttrEscape ()</h3> 149<pre class="programlisting">int xmlSaveSetAttrEscape (<a href="libxml2-xmlsave.html#xmlSaveCtxtPtr">xmlSaveCtxtPtr</a> ctxt, <br> <a href="libxml2-encoding.html#xmlCharEncodingOutputFunc">xmlCharEncodingOutputFunc</a> escape)<br> 150</pre> 151<p>Set a custom escaping function to be used for text in <a href="libxml2-SAX.html#attribute">attribute</a> content</p> 152<div class="variablelist"><table border="0"> 153<col align="left"> 154<tbody> 155<tr> 156<td><span class="term"><i><tt>ctxt</tt></i>:</span></td> 157<td>a document saving context</td> 158</tr> 159<tr> 160<td><span class="term"><i><tt>escape</tt></i>:</span></td> 161<td>the escaping function</td> 162</tr> 163<tr> 164<td><span class="term"><i><tt>Returns</tt></i>:</span></td> 165<td>0 if successful or -1 in case of error.</td> 166</tr> 167</tbody> 168</table></div> 169</div> 170<hr> 171<div class="refsect2" lang="en"> 172<h3> 173<a name="xmlSaveSetEscape"></a>xmlSaveSetEscape ()</h3> 174<pre class="programlisting">int xmlSaveSetEscape (<a href="libxml2-xmlsave.html#xmlSaveCtxtPtr">xmlSaveCtxtPtr</a> ctxt, <br> <a href="libxml2-encoding.html#xmlCharEncodingOutputFunc">xmlCharEncodingOutputFunc</a> escape)<br> 175</pre> 176<p>Set a custom escaping function to be used for text in element content</p> 177<div class="variablelist"><table border="0"> 178<col align="left"> 179<tbody> 180<tr> 181<td><span class="term"><i><tt>ctxt</tt></i>:</span></td> 182<td>a document saving context</td> 183</tr> 184<tr> 185<td><span class="term"><i><tt>escape</tt></i>:</span></td> 186<td>the escaping function</td> 187</tr> 188<tr> 189<td><span class="term"><i><tt>Returns</tt></i>:</span></td> 190<td>0 if successful or -1 in case of error.</td> 191</tr> 192</tbody> 193</table></div> 194</div> 195<hr> 196<div class="refsect2" lang="en"> 197<h3> 198<a name="xmlSaveToBuffer"></a>xmlSaveToBuffer ()</h3> 199<pre class="programlisting"><a href="libxml2-xmlsave.html#xmlSaveCtxtPtr">xmlSaveCtxtPtr</a> xmlSaveToBuffer (<a href="libxml2-tree.html#xmlBufferPtr">xmlBufferPtr</a> buffer, <br> const char * encoding, <br> int options)<br> 200</pre> 201<p>Create a document saving context serializing to a buffer with the encoding and the options given</p> 202<div class="variablelist"><table border="0"> 203<col align="left"> 204<tbody> 205<tr> 206<td><span class="term"><i><tt>buffer</tt></i>:</span></td> 207<td>a buffer</td> 208</tr> 209<tr> 210<td><span class="term"><i><tt>encoding</tt></i>:</span></td> 211<td>the encoding name to use or NULL</td> 212</tr> 213<tr> 214<td><span class="term"><i><tt>options</tt></i>:</span></td> 215<td>a set of xmlSaveOptions</td> 216</tr> 217<tr> 218<td><span class="term"><i><tt>Returns</tt></i>:</span></td> 219<td>a new serialization context or NULL in case of error.</td> 220</tr> 221</tbody> 222</table></div> 223</div> 224<hr> 225<div class="refsect2" lang="en"> 226<h3> 227<a name="xmlSaveToFd"></a>xmlSaveToFd ()</h3> 228<pre class="programlisting"><a href="libxml2-xmlsave.html#xmlSaveCtxtPtr">xmlSaveCtxtPtr</a> xmlSaveToFd (int fd, <br> const char * encoding, <br> int options)<br> 229</pre> 230<p>Create a document saving context serializing to a file descriptor with the encoding and the options given.</p> 231<div class="variablelist"><table border="0"> 232<col align="left"> 233<tbody> 234<tr> 235<td><span class="term"><i><tt>fd</tt></i>:</span></td> 236<td>a file descriptor number</td> 237</tr> 238<tr> 239<td><span class="term"><i><tt>encoding</tt></i>:</span></td> 240<td>the encoding name to use or NULL</td> 241</tr> 242<tr> 243<td><span class="term"><i><tt>options</tt></i>:</span></td> 244<td>a set of xmlSaveOptions</td> 245</tr> 246<tr> 247<td><span class="term"><i><tt>Returns</tt></i>:</span></td> 248<td>a new serialization context or NULL in case of error.</td> 249</tr> 250</tbody> 251</table></div> 252</div> 253<hr> 254<div class="refsect2" lang="en"> 255<h3> 256<a name="xmlSaveToFilename"></a>xmlSaveToFilename ()</h3> 257<pre class="programlisting"><a href="libxml2-xmlsave.html#xmlSaveCtxtPtr">xmlSaveCtxtPtr</a> xmlSaveToFilename (const char * filename, <br> const char * encoding, <br> int options)<br> 258</pre> 259<p>Create a document saving context serializing to a filename or possibly to an URL (but this is less reliable) with the encoding and the options given.</p> 260<div class="variablelist"><table border="0"> 261<col align="left"> 262<tbody> 263<tr> 264<td><span class="term"><i><tt>filename</tt></i>:</span></td> 265<td>a file name or an URL</td> 266</tr> 267<tr> 268<td><span class="term"><i><tt>encoding</tt></i>:</span></td> 269<td>the encoding name to use or NULL</td> 270</tr> 271<tr> 272<td><span class="term"><i><tt>options</tt></i>:</span></td> 273<td>a set of xmlSaveOptions</td> 274</tr> 275<tr> 276<td><span class="term"><i><tt>Returns</tt></i>:</span></td> 277<td>a new serialization context or NULL in case of error.</td> 278</tr> 279</tbody> 280</table></div> 281</div> 282<hr> 283<div class="refsect2" lang="en"> 284<h3> 285<a name="xmlSaveToIO"></a>xmlSaveToIO ()</h3> 286<pre class="programlisting"><a href="libxml2-xmlsave.html#xmlSaveCtxtPtr">xmlSaveCtxtPtr</a> xmlSaveToIO (<a href="libxml2-xmlIO.html#xmlOutputWriteCallback">xmlOutputWriteCallback</a> iowrite, <br> <a href="libxml2-xmlIO.html#xmlOutputCloseCallback">xmlOutputCloseCallback</a> ioclose, <br> void * ioctx, <br> const char * encoding, <br> int options)<br> 287</pre> 288<p>Create a document saving context serializing to a file descriptor with the encoding and the options given</p> 289<div class="variablelist"><table border="0"> 290<col align="left"> 291<tbody> 292<tr> 293<td><span class="term"><i><tt>iowrite</tt></i>:</span></td> 294<td>an I/O write function</td> 295</tr> 296<tr> 297<td><span class="term"><i><tt>ioclose</tt></i>:</span></td> 298<td>an I/O close function</td> 299</tr> 300<tr> 301<td><span class="term"><i><tt>ioctx</tt></i>:</span></td> 302<td>an I/O handler</td> 303</tr> 304<tr> 305<td><span class="term"><i><tt>encoding</tt></i>:</span></td> 306<td>the encoding name to use or NULL</td> 307</tr> 308<tr> 309<td><span class="term"><i><tt>options</tt></i>:</span></td> 310<td>a set of xmlSaveOptions</td> 311</tr> 312<tr> 313<td><span class="term"><i><tt>Returns</tt></i>:</span></td> 314<td>a new serialization context or NULL in case of error.</td> 315</tr> 316</tbody> 317</table></div> 318</div> 319<hr> 320<div class="refsect2" lang="en"> 321<h3> 322<a name="xmlSaveTree"></a>xmlSaveTree ()</h3> 323<pre class="programlisting">long xmlSaveTree (<a href="libxml2-xmlsave.html#xmlSaveCtxtPtr">xmlSaveCtxtPtr</a> ctxt, <br> <a href="libxml2-tree.html#xmlNodePtr">xmlNodePtr</a> cur)<br> 324</pre> 325<p>Save a subtree starting at the node parameter to a saving context TODO: The function is not fully implemented yet as it does not return the byte count but 0 instead</p> 326<div class="variablelist"><table border="0"> 327<col align="left"> 328<tbody> 329<tr> 330<td><span class="term"><i><tt>ctxt</tt></i>:</span></td> 331<td>a document saving context</td> 332</tr> 333<tr> 334<td><span class="term"><i><tt>cur</tt></i>:</span></td> 335<td></td> 336</tr> 337<tr> 338<td><span class="term"><i><tt>Returns</tt></i>:</span></td> 339<td>the number of byte written or -1 in case of error</td> 340</tr> 341</tbody> 342</table></div> 343</div> 344<hr> 345</div> 346</div> 347</body> 348</html> 349