* xmlSaveFormatFileEnc: * @filename: the filename or URL to output * @cur: the document being saved * @encoding: the name of the encoding to use or NULL. * @format: should formatting spaces be added. * * Dump an XML document to a file or an URL. * * Returns the number of bytes written or -1 in case of error. * Note that @format = 1 provide node indenting only if xmlIndentTreeOutput =
| 2908 | * or xmlKeepBlanksDefault(0) was called |
| 2909 | */ |
| 2910 | int |
| 2911 | xmlSaveFormatFileEnc( const char * filename, xmlDocPtr cur, |
| 2912 | const char * encoding, int format ) { |
| 2913 | xmlSaveCtxt ctxt; |
| 2914 | xmlOutputBufferPtr buf; |
| 2915 | xmlCharEncodingHandlerPtr handler = NULL; |
| 2916 | int ret; |
| 2917 | |
| 2918 | if (cur == NULL) |
| 2919 | return(-1); |
| 2920 | |
| 2921 | if (encoding == NULL) |
| 2922 | encoding = (const char *) cur->encoding; |
| 2923 | |
| 2924 | if (encoding != NULL) { |
| 2925 | int res; |
| 2926 | |
| 2927 | res = xmlOpenCharEncodingHandler(encoding, /* output */ 1, &handler); |
| 2928 | if (res != XML_ERR_OK) |
| 2929 | return(-1); |
| 2930 | } |
| 2931 | |
| 2932 | #ifdef LIBXML_ZLIB_ENABLED |
| 2933 | if (cur->compression < 0) cur->compression = xmlGetCompressMode(); |
| 2934 | #endif |
| 2935 | /* |
| 2936 | * save the content to a temp buffer. |
| 2937 | */ |
| 2938 | buf = xmlOutputBufferCreateFilename(filename, handler, cur->compression); |
| 2939 | if (buf == NULL) return(-1); |
| 2940 | memset(&ctxt, 0, sizeof(ctxt)); |
| 2941 | ctxt.buf = buf; |
| 2942 | ctxt.level = 0; |
| 2943 | ctxt.format = format ? 1 : 0; |
| 2944 | ctxt.encoding = (const xmlChar *) encoding; |
| 2945 | xmlSaveCtxtInit(&ctxt); |
| 2946 | ctxt.options |= XML_SAVE_AS_XML; |
| 2947 | |
| 2948 | xmlDocContentDumpOutput(&ctxt, cur); |
| 2949 | |
| 2950 | ret = xmlOutputBufferClose(buf); |
| 2951 | return(ret); |
| 2952 | } |
| 2953 | |
| 2954 | |
| 2955 | /** |
no test coverage detected