* xmlDocContentDumpOutput: * @cur: the document * * Dump an XML document. */
| 1356 | * Dump an XML document. |
| 1357 | */ |
| 1358 | static int |
| 1359 | xmlDocContentDumpOutput(xmlSaveCtxtPtr ctxt, xmlDocPtr cur) { |
| 1360 | #ifdef LIBXML_HTML_ENABLED |
| 1361 | xmlDtdPtr dtd; |
| 1362 | int is_xhtml = 0; |
| 1363 | #endif |
| 1364 | const xmlChar *oldenc = cur->encoding; |
| 1365 | const xmlChar *oldctxtenc = ctxt->encoding; |
| 1366 | const xmlChar *encoding = ctxt->encoding; |
| 1367 | xmlCharEncodingOutputFunc oldescape = ctxt->escape; |
| 1368 | xmlCharEncodingOutputFunc oldescapeAttr = ctxt->escapeAttr; |
| 1369 | xmlOutputBufferPtr buf = ctxt->buf; |
| 1370 | xmlCharEncoding enc; |
| 1371 | int switched_encoding = 0; |
| 1372 | |
| 1373 | xmlInitParser(); |
| 1374 | |
| 1375 | if ((cur->type != XML_HTML_DOCUMENT_NODE) && |
| 1376 | (cur->type != XML_DOCUMENT_NODE)) |
| 1377 | return(-1); |
| 1378 | |
| 1379 | if (ctxt->encoding != NULL) { |
| 1380 | cur->encoding = BAD_CAST ctxt->encoding; |
| 1381 | } else if (cur->encoding != NULL) { |
| 1382 | encoding = cur->encoding; |
| 1383 | } |
| 1384 | |
| 1385 | if (((cur->type == XML_HTML_DOCUMENT_NODE) && |
| 1386 | ((ctxt->options & XML_SAVE_AS_XML) == 0) && |
| 1387 | ((ctxt->options & XML_SAVE_XHTML) == 0)) || |
| 1388 | (ctxt->options & XML_SAVE_AS_HTML)) { |
| 1389 | #ifdef LIBXML_HTML_ENABLED |
| 1390 | if (encoding != NULL) |
| 1391 | htmlSetMetaEncoding(cur, (const xmlChar *) encoding); |
| 1392 | if (encoding == NULL) |
| 1393 | encoding = htmlGetMetaEncoding(cur); |
| 1394 | if (encoding == NULL) |
| 1395 | encoding = BAD_CAST "HTML"; |
| 1396 | if ((encoding != NULL) && (oldctxtenc == NULL) && |
| 1397 | (buf->encoder == NULL) && (buf->conv == NULL)) { |
| 1398 | if (xmlSaveSwitchEncoding(ctxt, (const char*) encoding) < 0) { |
| 1399 | cur->encoding = oldenc; |
| 1400 | return(-1); |
| 1401 | } |
| 1402 | } |
| 1403 | if (ctxt->options & XML_SAVE_FORMAT) |
| 1404 | htmlDocContentDumpFormatOutput(buf, cur, |
| 1405 | (const char *)encoding, 1); |
| 1406 | else |
| 1407 | htmlDocContentDumpFormatOutput(buf, cur, |
| 1408 | (const char *)encoding, 0); |
| 1409 | if (ctxt->encoding != NULL) |
| 1410 | cur->encoding = oldenc; |
| 1411 | return(0); |
| 1412 | #else |
| 1413 | return(-1); |
| 1414 | #endif |
| 1415 | } else if ((cur->type == XML_DOCUMENT_NODE) || |
no test coverage detected