* xmlSaveFormatFileTo: * @buf: an output I/O buffer * @cur: the document * @encoding: the encoding if any assuming the I/O layer handles the transcoding * @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
| 2869 | * returns: the number of bytes written or -1 in case of failure. |
| 2870 | */ |
| 2871 | int |
| 2872 | xmlSaveFormatFileTo(xmlOutputBufferPtr buf, xmlDocPtr cur, |
| 2873 | const char *encoding, int format) |
| 2874 | { |
| 2875 | xmlSaveCtxt ctxt; |
| 2876 | int ret; |
| 2877 | |
| 2878 | if (buf == NULL) return(-1); |
| 2879 | if ((cur == NULL) || |
| 2880 | ((cur->type != XML_DOCUMENT_NODE) && |
| 2881 | (cur->type != XML_HTML_DOCUMENT_NODE))) { |
| 2882 | xmlOutputBufferClose(buf); |
| 2883 | return(-1); |
| 2884 | } |
| 2885 | memset(&ctxt, 0, sizeof(ctxt)); |
| 2886 | ctxt.buf = buf; |
| 2887 | ctxt.level = 0; |
| 2888 | ctxt.format = format ? 1 : 0; |
| 2889 | ctxt.encoding = (const xmlChar *) encoding; |
| 2890 | xmlSaveCtxtInit(&ctxt); |
| 2891 | ctxt.options |= XML_SAVE_AS_XML; |
| 2892 | xmlDocContentDumpOutput(&ctxt, cur); |
| 2893 | ret = xmlOutputBufferClose(buf); |
| 2894 | return (ret); |
| 2895 | } |
| 2896 | |
| 2897 | /** |
| 2898 | * xmlSaveFormatFileEnc: |
no test coverage detected