* xmlSaveFormatFileTo: * @buf: an output I/O buffer * @cur: the document * @encoding: the encoding if any assuming the I/O layer handles the trancoding * @format: should formatting spaces been added * * Dump an XML document to an I/O buffer. * Warning ! This call xmlOutputBufferClose() on buf which is not available * after this call. * * returns: the number of bytes written or -1 in c
| 2279 | * returns: the number of bytes written or -1 in case of failure. |
| 2280 | */ |
| 2281 | int |
| 2282 | xmlSaveFormatFileTo(xmlOutputBufferPtr buf, xmlDocPtr cur, |
| 2283 | const char *encoding, int format) |
| 2284 | { |
| 2285 | xmlSaveCtxt ctxt; |
| 2286 | int ret; |
| 2287 | |
| 2288 | if (buf == NULL) return(-1); |
| 2289 | if ((cur == NULL) || |
| 2290 | ((cur->type != XML_DOCUMENT_NODE) && |
| 2291 | (cur->type != XML_HTML_DOCUMENT_NODE))) { |
| 2292 | xmlOutputBufferClose(buf); |
| 2293 | return(-1); |
| 2294 | } |
| 2295 | memset(&ctxt, 0, sizeof(ctxt)); |
| 2296 | ctxt.doc = cur; |
| 2297 | ctxt.buf = buf; |
| 2298 | ctxt.level = 0; |
| 2299 | ctxt.format = format; |
| 2300 | ctxt.encoding = (const xmlChar *) encoding; |
| 2301 | xmlSaveCtxtInit(&ctxt); |
| 2302 | xmlDocContentDumpOutput(&ctxt, cur); |
| 2303 | ret = xmlOutputBufferClose(buf); |
| 2304 | return (ret); |
| 2305 | } |
| 2306 | |
| 2307 | /** |
| 2308 | * xmlSaveFormatFileEnc: |