* htmlDocDumpMemoryFormat: * @cur: the document * @mem: OUT: the memory pointer * @size: OUT: the memory length * @format: should formatting spaces been added * * Dump an HTML document in memory and return the xmlChar * and it's size. * It's up to the caller to free the memory. */
| 516 | * It's up to the caller to free the memory. |
| 517 | */ |
| 518 | void |
| 519 | htmlDocDumpMemoryFormat(xmlDocPtr cur, xmlChar**mem, int *size, int format) { |
| 520 | xmlOutputBufferPtr buf; |
| 521 | xmlCharEncodingHandlerPtr handler = NULL; |
| 522 | const char *encoding; |
| 523 | |
| 524 | xmlInitParser(); |
| 525 | |
| 526 | if ((mem == NULL) || (size == NULL)) |
| 527 | return; |
| 528 | if (cur == NULL) { |
| 529 | *mem = NULL; |
| 530 | *size = 0; |
| 531 | return; |
| 532 | } |
| 533 | |
| 534 | encoding = (const char *) htmlGetMetaEncoding(cur); |
| 535 | |
| 536 | if (encoding != NULL) { |
| 537 | xmlCharEncoding enc; |
| 538 | |
| 539 | enc = xmlParseCharEncoding(encoding); |
| 540 | if (enc != cur->charset) { |
| 541 | if (cur->charset != XML_CHAR_ENCODING_UTF8) { |
| 542 | /* |
| 543 | * Not supported yet |
| 544 | */ |
| 545 | *mem = NULL; |
| 546 | *size = 0; |
| 547 | return; |
| 548 | } |
| 549 | |
| 550 | handler = xmlFindCharEncodingHandler(encoding); |
| 551 | if (handler == NULL) { |
| 552 | *mem = NULL; |
| 553 | *size = 0; |
| 554 | return; |
| 555 | } |
| 556 | } else { |
| 557 | handler = xmlFindCharEncodingHandler(encoding); |
| 558 | } |
| 559 | } |
| 560 | |
| 561 | /* |
| 562 | * Fallback to HTML or ASCII when the encoding is unspecified |
| 563 | */ |
| 564 | if (handler == NULL) |
| 565 | handler = xmlFindCharEncodingHandler("HTML"); |
| 566 | if (handler == NULL) |
| 567 | handler = xmlFindCharEncodingHandler("ascii"); |
| 568 | |
| 569 | buf = xmlAllocOutputBuffer(handler); |
| 570 | if (buf == NULL) { |
| 571 | *mem = NULL; |
| 572 | *size = 0; |
| 573 | return; |
| 574 | } |
| 575 |