* htmlSaveFile: * @filename: the filename (or URL) * @cur: the document * * Dump an HTML document to a file. If @filename is "-" the stdout file is * used. * returns: the number of byte written or -1 in case of failure. */
| 1079 | * returns: the number of byte written or -1 in case of failure. |
| 1080 | */ |
| 1081 | int |
| 1082 | htmlSaveFile(const char *filename, xmlDocPtr cur) { |
| 1083 | xmlOutputBufferPtr buf; |
| 1084 | xmlCharEncodingHandlerPtr handler = NULL; |
| 1085 | const char *encoding; |
| 1086 | int ret; |
| 1087 | |
| 1088 | if ((cur == NULL) || (filename == NULL)) |
| 1089 | return(-1); |
| 1090 | |
| 1091 | xmlInitParser(); |
| 1092 | |
| 1093 | encoding = (const char *) htmlGetMetaEncoding(cur); |
| 1094 | |
| 1095 | if (encoding != NULL) { |
| 1096 | xmlCharEncoding enc; |
| 1097 | |
| 1098 | enc = xmlParseCharEncoding(encoding); |
| 1099 | if (enc != cur->charset) { |
| 1100 | if (cur->charset != XML_CHAR_ENCODING_UTF8) { |
| 1101 | /* |
| 1102 | * Not supported yet |
| 1103 | */ |
| 1104 | return(-1); |
| 1105 | } |
| 1106 | |
| 1107 | handler = xmlFindCharEncodingHandler(encoding); |
| 1108 | if (handler == NULL) |
| 1109 | return(-1); |
| 1110 | } |
| 1111 | } |
| 1112 | |
| 1113 | /* |
| 1114 | * Fallback to HTML or ASCII when the encoding is unspecified |
| 1115 | */ |
| 1116 | if (handler == NULL) |
| 1117 | handler = xmlFindCharEncodingHandler("HTML"); |
| 1118 | if (handler == NULL) |
| 1119 | handler = xmlFindCharEncodingHandler("ascii"); |
| 1120 | |
| 1121 | /* |
| 1122 | * save the content to a temp buffer. |
| 1123 | */ |
| 1124 | buf = xmlOutputBufferCreateFilename(filename, handler, cur->compression); |
| 1125 | if (buf == NULL) return(0); |
| 1126 | |
| 1127 | htmlDocContentDumpOutput(buf, cur, NULL); |
| 1128 | |
| 1129 | ret = xmlOutputBufferClose(buf); |
| 1130 | return(ret); |
| 1131 | } |
| 1132 | |
| 1133 | /** |
| 1134 | * htmlSaveFileFormat: |