* htmlNodeDumpFileFormat: * @out: the FILE pointer * @doc: the document * @cur: the current node * @encoding: the document encoding * @format: should formatting spaces been added * * Dump an HTML node, recursive behaviour,children are printed too. * * TODO: if encoding == NULL try to save in the doc encoding * * returns: the number of byte written or -1 in case of failure. */
| 452 | * returns: the number of byte written or -1 in case of failure. |
| 453 | */ |
| 454 | int |
| 455 | htmlNodeDumpFileFormat(FILE *out, xmlDocPtr doc, |
| 456 | xmlNodePtr cur, const char *encoding, int format) { |
| 457 | xmlOutputBufferPtr buf; |
| 458 | xmlCharEncodingHandlerPtr handler = NULL; |
| 459 | int ret; |
| 460 | |
| 461 | xmlInitParser(); |
| 462 | |
| 463 | if (encoding != NULL) { |
| 464 | xmlCharEncoding enc; |
| 465 | |
| 466 | enc = xmlParseCharEncoding(encoding); |
| 467 | if (enc != XML_CHAR_ENCODING_UTF8) { |
| 468 | handler = xmlFindCharEncodingHandler(encoding); |
| 469 | if (handler == NULL) |
| 470 | return(-1); |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | /* |
| 475 | * Fallback to HTML or ASCII when the encoding is unspecified |
| 476 | */ |
| 477 | if (handler == NULL) |
| 478 | handler = xmlFindCharEncodingHandler("HTML"); |
| 479 | if (handler == NULL) |
| 480 | handler = xmlFindCharEncodingHandler("ascii"); |
| 481 | |
| 482 | /* |
| 483 | * save the content to a temp buffer. |
| 484 | */ |
| 485 | buf = xmlOutputBufferCreateFile(out, handler); |
| 486 | if (buf == NULL) return(0); |
| 487 | |
| 488 | htmlNodeDumpFormatOutput(buf, doc, cur, encoding, format); |
| 489 | |
| 490 | ret = xmlOutputBufferClose(buf); |
| 491 | return(ret); |
| 492 | } |
| 493 | |
| 494 | /** |
| 495 | * htmlNodeDumpFile: |