MCPcopy Create free account
hub / github.com/KhronosGroup/OpenCOLLADA / htmlSaveFileFormat

Function htmlSaveFileFormat

Externals/LibXML/HTMLtree.c:1144–1195  ·  view source on GitHub ↗

* htmlSaveFileFormat: * @filename: the filename * @cur: the document * @format: should formatting spaces been added * @encoding: the document encoding * * Dump an HTML document to a file using a given encoding. * * returns: the number of byte written or -1 in case of failure. */

Source from the content-addressed store, hash-verified

1142 * returns: the number of byte written or -1 in case of failure.
1143 */
1144int
1145htmlSaveFileFormat(const char *filename, xmlDocPtr cur,
1146 const char *encoding, int format) {
1147 xmlOutputBufferPtr buf;
1148 xmlCharEncodingHandlerPtr handler = NULL;
1149 int ret;
1150
1151 if ((cur == NULL) || (filename == NULL))
1152 return(-1);
1153
1154 xmlInitParser();
1155
1156 if (encoding != NULL) {
1157 xmlCharEncoding enc;
1158
1159 enc = xmlParseCharEncoding(encoding);
1160 if (enc != cur->charset) {
1161 if (cur->charset != XML_CHAR_ENCODING_UTF8) {
1162 /*
1163 * Not supported yet
1164 */
1165 return(-1);
1166 }
1167
1168 handler = xmlFindCharEncodingHandler(encoding);
1169 if (handler == NULL)
1170 return(-1);
1171 htmlSetMetaEncoding(cur, (const xmlChar *) encoding);
1172 }
1173 } else {
1174 htmlSetMetaEncoding(cur, (const xmlChar *) "UTF-8");
1175 }
1176
1177 /*
1178 * Fallback to HTML or ASCII when the encoding is unspecified
1179 */
1180 if (handler == NULL)
1181 handler = xmlFindCharEncodingHandler("HTML");
1182 if (handler == NULL)
1183 handler = xmlFindCharEncodingHandler("ascii");
1184
1185 /*
1186 * save the content to a temp buffer.
1187 */
1188 buf = xmlOutputBufferCreateFilename(filename, handler, 0);
1189 if (buf == NULL) return(0);
1190
1191 htmlDocContentDumpFormatOutput(buf, cur, encoding, format);
1192
1193 ret = xmlOutputBufferClose(buf);
1194 return(ret);
1195}
1196
1197/**
1198 * htmlSaveFileEnc:

Callers 3

parseAndPrintFileFunction · 0.85
test_htmlSaveFileFormatFunction · 0.85
htmlSaveFileEncFunction · 0.85

Calls 6

xmlParseCharEncodingFunction · 0.85
htmlSetMetaEncodingFunction · 0.85
xmlOutputBufferCloseFunction · 0.85

Tested by 1

test_htmlSaveFileFormatFunction · 0.68