OLD | NEW |
1 /* | 1 /* |
2 * xmlsave.c: Implemetation of the document serializer | 2 * xmlsave.c: Implemetation of the document serializer |
3 * | 3 * |
4 * See Copyright for the status of this software. | 4 * See Copyright for the status of this software. |
5 * | 5 * |
6 * daniel@veillard.com | 6 * daniel@veillard.com |
7 */ | 7 */ |
8 | 8 |
9 #define IN_LIBXML | 9 #define IN_LIBXML |
10 #include "libxml.h" | 10 #include "libxml.h" |
11 | 11 |
12 #include <string.h> | 12 #include <string.h> |
13 #include <libxml/xmlmemory.h> | 13 #include <libxml/xmlmemory.h> |
14 #include <libxml/parserInternals.h> | 14 #include <libxml/parserInternals.h> |
15 #include <libxml/tree.h> | 15 #include <libxml/tree.h> |
16 #include <libxml/xmlsave.h> | 16 #include <libxml/xmlsave.h> |
17 | 17 |
18 #define MAX_INDENT 60 | 18 #define MAX_INDENT 60 |
19 | 19 |
20 #include <libxml/HTMLtree.h> | 20 #include <libxml/HTMLtree.h> |
21 | 21 |
| 22 #include "buf.h" |
| 23 #include "enc.h" |
| 24 #include "save.h" |
| 25 |
22 /************************************************************************ | 26 /************************************************************************ |
23 * * | 27 * * |
24 * XHTML detection * | 28 * XHTML detection * |
25 * * | 29 * * |
26 ************************************************************************/ | 30 ************************************************************************/ |
27 #define XHTML_STRICT_PUBLIC_ID BAD_CAST \ | 31 #define XHTML_STRICT_PUBLIC_ID BAD_CAST \ |
28 "-//W3C//DTD XHTML 1.0 Strict//EN" | 32 "-//W3C//DTD XHTML 1.0 Strict//EN" |
29 #define XHTML_STRICT_SYSTEM_ID BAD_CAST \ | 33 #define XHTML_STRICT_SYSTEM_ID BAD_CAST \ |
30 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" | 34 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" |
31 #define XHTML_FRAME_PUBLIC_ID BAD_CAST \ | 35 #define XHTML_FRAME_PUBLIC_ID BAD_CAST \ |
(...skipping 27 matching lines...) Expand all Loading... |
59 if (systemID != NULL) { | 63 if (systemID != NULL) { |
60 if (xmlStrEqual(systemID, XHTML_STRICT_SYSTEM_ID)) return(1); | 64 if (xmlStrEqual(systemID, XHTML_STRICT_SYSTEM_ID)) return(1); |
61 if (xmlStrEqual(systemID, XHTML_FRAME_SYSTEM_ID)) return(1); | 65 if (xmlStrEqual(systemID, XHTML_FRAME_SYSTEM_ID)) return(1); |
62 if (xmlStrEqual(systemID, XHTML_TRANS_SYSTEM_ID)) return(1); | 66 if (xmlStrEqual(systemID, XHTML_TRANS_SYSTEM_ID)) return(1); |
63 } | 67 } |
64 return(0); | 68 return(0); |
65 } | 69 } |
66 | 70 |
67 #ifdef LIBXML_OUTPUT_ENABLED | 71 #ifdef LIBXML_OUTPUT_ENABLED |
68 | 72 |
69 #define TODO » » » » » » » » \ | 73 #define TODO» » » » » » » » \ |
70 xmlGenericError(xmlGenericErrorContext, \ | 74 xmlGenericError(xmlGenericErrorContext, \ |
71 "Unimplemented block at %s:%d\n", \ | 75 "Unimplemented block at %s:%d\n", \ |
72 __FILE__, __LINE__); | 76 __FILE__, __LINE__); |
73 | 77 |
74 struct _xmlSaveCtxt { | 78 struct _xmlSaveCtxt { |
75 void *_private; | 79 void *_private; |
76 int type; | 80 int type; |
77 int fd; | 81 int fd; |
78 const xmlChar *filename; | 82 const xmlChar *filename; |
79 const xmlChar *encoding; | 83 const xmlChar *encoding; |
80 xmlCharEncodingHandlerPtr handler; | 84 xmlCharEncodingHandlerPtr handler; |
81 xmlOutputBufferPtr buf; | 85 xmlOutputBufferPtr buf; |
82 xmlDocPtr doc; | 86 xmlDocPtr doc; |
83 int options; | 87 int options; |
84 int level; | 88 int level; |
85 int format; | 89 int format; |
86 char indent[MAX_INDENT + 1]; /* array for indenting output */ | 90 char indent[MAX_INDENT + 1]; /* array for indenting output */ |
87 int indent_nr; | 91 int indent_nr; |
88 int indent_size; | 92 int indent_size; |
89 xmlCharEncodingOutputFunc escape; /* used for element content */ | 93 xmlCharEncodingOutputFunc escape; /* used for element content */ |
90 xmlCharEncodingOutputFunc escapeAttr;/* used for attribute content */ | 94 xmlCharEncodingOutputFunc escapeAttr;/* used for attribute content */ |
91 }; | 95 }; |
92 | 96 |
93 /************************************************************************ | 97 /************************************************************************ |
94 * * | 98 * * |
95 * » » » Output error handlers» » » » * | 99 *» » » Output error handlers» » » » * |
96 * * | 100 * * |
97 ************************************************************************/ | 101 ************************************************************************/ |
98 /** | 102 /** |
99 * xmlSaveErrMemory: | 103 * xmlSaveErrMemory: |
100 * @extra: extra informations | 104 * @extra: extra informations |
101 * | 105 * |
102 * Handle an out of memory condition | 106 * Handle an out of memory condition |
103 */ | 107 */ |
104 static void | 108 static void |
105 xmlSaveErrMemory(const char *extra) | 109 xmlSaveErrMemory(const char *extra) |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 static int | 207 static int |
204 xmlEscapeEntities(unsigned char* out, int *outlen, | 208 xmlEscapeEntities(unsigned char* out, int *outlen, |
205 const xmlChar* in, int *inlen) { | 209 const xmlChar* in, int *inlen) { |
206 unsigned char* outstart = out; | 210 unsigned char* outstart = out; |
207 const unsigned char* base = in; | 211 const unsigned char* base = in; |
208 unsigned char* outend = out + *outlen; | 212 unsigned char* outend = out + *outlen; |
209 const unsigned char* inend; | 213 const unsigned char* inend; |
210 int val; | 214 int val; |
211 | 215 |
212 inend = in + (*inlen); | 216 inend = in + (*inlen); |
213 | 217 |
214 while ((in < inend) && (out < outend)) { | 218 while ((in < inend) && (out < outend)) { |
215 » if (*in == '<') { | 219 » if (*in == '<') { |
216 if (outend - out < 4) break; | 220 if (outend - out < 4) break; |
217 *out++ = '&'; | 221 *out++ = '&'; |
218 *out++ = 'l'; | 222 *out++ = 'l'; |
219 *out++ = 't'; | 223 *out++ = 't'; |
220 *out++ = ';'; | 224 *out++ = ';'; |
221 in++; | 225 in++; |
222 continue; | 226 continue; |
223 } else if (*in == '>') { | 227 } else if (*in == '>') { |
224 if (outend - out < 4) break; | 228 if (outend - out < 4) break; |
225 *out++ = '&'; | 229 *out++ = '&'; |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 */ | 405 */ |
402 | 406 |
403 /* Re-check this option as it may already have been set */ | 407 /* Re-check this option as it may already have been set */ |
404 if ((ret->options & XML_SAVE_NO_EMPTY) && ! (options & XML_SAVE_NO_EMPTY)) { | 408 if ((ret->options & XML_SAVE_NO_EMPTY) && ! (options & XML_SAVE_NO_EMPTY)) { |
405 options |= XML_SAVE_NO_EMPTY; | 409 options |= XML_SAVE_NO_EMPTY; |
406 } | 410 } |
407 | 411 |
408 ret->options = options; | 412 ret->options = options; |
409 if (options & XML_SAVE_FORMAT) | 413 if (options & XML_SAVE_FORMAT) |
410 ret->format = 1; | 414 ret->format = 1; |
| 415 else if (options & XML_SAVE_WSNONSIG) |
| 416 ret->format = 2; |
411 | 417 |
412 return(ret); | 418 return(ret); |
413 } | 419 } |
414 | 420 |
415 /************************************************************************ | 421 /************************************************************************ |
416 * * | 422 * * |
417 * » » Dumping XML tree content to a simple buffer» » * | 423 *» » Dumping XML tree content to a simple buffer» » * |
418 * * | 424 * * |
419 ************************************************************************/ | 425 ************************************************************************/ |
420 /** | 426 /** |
421 * xmlAttrSerializeContent: | 427 * xmlAttrSerializeContent: |
422 * @buf: the XML buffer output | 428 * @buf: the XML buffer output |
423 * @doc: the document | 429 * @doc: the document |
424 * @attr: the attribute pointer | 430 * @attr: the attribute pointer |
425 * | 431 * |
426 * Serialize the attribute in the buffer | 432 * Serialize the attribute in the buffer |
427 */ | 433 */ |
428 static void | 434 static void |
429 xmlAttrSerializeContent(xmlOutputBufferPtr buf, xmlAttrPtr attr) | 435 xmlAttrSerializeContent(xmlOutputBufferPtr buf, xmlAttrPtr attr) |
430 { | 436 { |
431 xmlNodePtr children; | 437 xmlNodePtr children; |
432 | 438 |
433 children = attr->children; | 439 children = attr->children; |
434 while (children != NULL) { | 440 while (children != NULL) { |
435 switch (children->type) { | 441 switch (children->type) { |
436 case XML_TEXT_NODE: | 442 case XML_TEXT_NODE: |
437 » xmlAttrSerializeTxtContent(buf->buffer, attr->doc, | 443 » xmlBufAttrSerializeTxtContent(buf->buffer, attr->doc, |
438 » » attr, children->content); | 444 » » attr, children->content); |
439 break; | 445 break; |
440 case XML_ENTITY_REF_NODE: | 446 case XML_ENTITY_REF_NODE: |
441 xmlBufferAdd(buf->buffer, BAD_CAST "&", 1); | 447 xmlBufAdd(buf->buffer, BAD_CAST "&", 1); |
442 xmlBufferAdd(buf->buffer, children->name, | 448 xmlBufAdd(buf->buffer, children->name, |
443 xmlStrlen(children->name)); | 449 xmlStrlen(children->name)); |
444 xmlBufferAdd(buf->buffer, BAD_CAST ";", 1); | 450 xmlBufAdd(buf->buffer, BAD_CAST ";", 1); |
445 break; | 451 break; |
446 default: | 452 default: |
447 /* should not happen unless we have a badly built tree */ | 453 /* should not happen unless we have a badly built tree */ |
448 break; | 454 break; |
449 } | 455 } |
450 children = children->next; | 456 children = children->next; |
451 } | 457 } |
452 } | 458 } |
453 | 459 |
| 460 /** |
| 461 * xmlBufDumpNotationTable: |
| 462 * @buf: an xmlBufPtr output |
| 463 * @table: A notation table |
| 464 * |
| 465 * This will dump the content of the notation table as an XML DTD definition |
| 466 */ |
| 467 void |
| 468 xmlBufDumpNotationTable(xmlBufPtr buf, xmlNotationTablePtr table) { |
| 469 xmlBufferPtr buffer; |
| 470 |
| 471 buffer = xmlBufferCreate(); |
| 472 if (buffer == NULL) { |
| 473 /* |
| 474 * TODO set the error in buf |
| 475 */ |
| 476 return; |
| 477 } |
| 478 xmlDumpNotationTable(buffer, table); |
| 479 xmlBufMergeBuffer(buf, buffer); |
| 480 } |
| 481 |
| 482 /** |
| 483 * xmlBufDumpElementDecl: |
| 484 * @buf: an xmlBufPtr output |
| 485 * @elem: An element table |
| 486 * |
| 487 * This will dump the content of the element declaration as an XML |
| 488 * DTD definition |
| 489 */ |
| 490 void |
| 491 xmlBufDumpElementDecl(xmlBufPtr buf, xmlElementPtr elem) { |
| 492 xmlBufferPtr buffer; |
| 493 |
| 494 buffer = xmlBufferCreate(); |
| 495 if (buffer == NULL) { |
| 496 /* |
| 497 * TODO set the error in buf |
| 498 */ |
| 499 return; |
| 500 } |
| 501 xmlDumpElementDecl(buffer, elem); |
| 502 xmlBufMergeBuffer(buf, buffer); |
| 503 } |
| 504 |
| 505 /** |
| 506 * xmlBufDumpAttributeDecl: |
| 507 * @buf: an xmlBufPtr output |
| 508 * @attr: An attribute declaration |
| 509 * |
| 510 * This will dump the content of the attribute declaration as an XML |
| 511 * DTD definition |
| 512 */ |
| 513 void |
| 514 xmlBufDumpAttributeDecl(xmlBufPtr buf, xmlAttributePtr attr) { |
| 515 xmlBufferPtr buffer; |
| 516 |
| 517 buffer = xmlBufferCreate(); |
| 518 if (buffer == NULL) { |
| 519 /* |
| 520 * TODO set the error in buf |
| 521 */ |
| 522 return; |
| 523 } |
| 524 xmlDumpAttributeDecl(buffer, attr); |
| 525 xmlBufMergeBuffer(buf, buffer); |
| 526 } |
| 527 |
| 528 /** |
| 529 * xmlBufDumpEntityDecl: |
| 530 * @buf: an xmlBufPtr output |
| 531 * @ent: An entity table |
| 532 * |
| 533 * This will dump the content of the entity table as an XML DTD definition |
| 534 */ |
| 535 void |
| 536 xmlBufDumpEntityDecl(xmlBufPtr buf, xmlEntityPtr ent) { |
| 537 xmlBufferPtr buffer; |
| 538 |
| 539 buffer = xmlBufferCreate(); |
| 540 if (buffer == NULL) { |
| 541 /* |
| 542 * TODO set the error in buf |
| 543 */ |
| 544 return; |
| 545 } |
| 546 xmlDumpEntityDecl(buffer, ent); |
| 547 xmlBufMergeBuffer(buf, buffer); |
| 548 } |
| 549 |
454 /************************************************************************ | 550 /************************************************************************ |
455 * * | 551 * * |
456 * » » Dumping XML tree content to an I/O output buffer» * | 552 *» » Dumping XML tree content to an I/O output buffer» * |
457 * * | 553 * * |
458 ************************************************************************/ | 554 ************************************************************************/ |
459 | 555 |
460 static int xmlSaveSwitchEncoding(xmlSaveCtxtPtr ctxt, const char *encoding) { | 556 static int xmlSaveSwitchEncoding(xmlSaveCtxtPtr ctxt, const char *encoding) { |
461 xmlOutputBufferPtr buf = ctxt->buf; | 557 xmlOutputBufferPtr buf = ctxt->buf; |
462 | 558 |
463 if ((encoding != NULL) && (buf->encoder == NULL) && (buf->conv == NULL)) { | 559 if ((encoding != NULL) && (buf->encoder == NULL) && (buf->conv == NULL)) { |
464 buf->encoder = xmlFindCharEncodingHandler((const char *)encoding); | 560 buf->encoder = xmlFindCharEncodingHandler((const char *)encoding); |
465 if (buf->encoder == NULL) { | 561 if (buf->encoder == NULL) { |
466 xmlSaveErr(XML_SAVE_UNKNOWN_ENCODING, NULL, | 562 xmlSaveErr(XML_SAVE_UNKNOWN_ENCODING, NULL, |
467 (const char *)encoding); | 563 (const char *)encoding); |
468 return(-1); | 564 return(-1); |
469 } | 565 } |
470 » buf->conv = xmlBufferCreate(); | 566 » buf->conv = xmlBufCreate(); |
471 if (buf->conv == NULL) { | 567 if (buf->conv == NULL) { |
472 xmlCharEncCloseFunc(buf->encoder); | 568 xmlCharEncCloseFunc(buf->encoder); |
473 xmlSaveErrMemory("creating encoding buffer"); | 569 xmlSaveErrMemory("creating encoding buffer"); |
474 return(-1); | 570 return(-1); |
475 } | 571 } |
476 /* | 572 /* |
477 * initialize the state, e.g. if outputting a BOM | 573 * initialize the state, e.g. if outputting a BOM |
478 */ | 574 */ |
479 » xmlCharEncOutFunc(buf->encoder, buf->conv, NULL); | 575 xmlCharEncOutput(buf, 1); |
480 } | 576 } |
481 return(0); | 577 return(0); |
482 } | 578 } |
483 | 579 |
484 static int xmlSaveClearEncoding(xmlSaveCtxtPtr ctxt) { | 580 static int xmlSaveClearEncoding(xmlSaveCtxtPtr ctxt) { |
485 xmlOutputBufferPtr buf = ctxt->buf; | 581 xmlOutputBufferPtr buf = ctxt->buf; |
486 xmlOutputBufferFlush(buf); | 582 xmlOutputBufferFlush(buf); |
487 xmlCharEncCloseFunc(buf->encoder); | 583 xmlCharEncCloseFunc(buf->encoder); |
488 xmlBufferFree(buf->conv); | 584 xmlBufFree(buf->conv); |
489 buf->encoder = NULL; | 585 buf->encoder = NULL; |
490 buf->conv = NULL; | 586 buf->conv = NULL; |
491 return(0); | 587 return(0); |
492 } | 588 } |
493 | 589 |
494 #ifdef LIBXML_HTML_ENABLED | 590 #ifdef LIBXML_HTML_ENABLED |
495 static void | 591 static void |
496 xhtmlNodeDumpOutput(xmlSaveCtxtPtr ctxt, xmlNodePtr cur); | 592 xhtmlNodeDumpOutput(xmlSaveCtxtPtr ctxt, xmlNodePtr cur); |
497 #endif | 593 #endif |
498 static void xmlNodeListDumpOutput(xmlSaveCtxtPtr ctxt, xmlNodePtr cur); | 594 static void xmlNodeListDumpOutput(xmlSaveCtxtPtr ctxt, xmlNodePtr cur); |
499 static void xmlNodeDumpOutputInternal(xmlSaveCtxtPtr ctxt, xmlNodePtr cur); | 595 static void xmlNodeDumpOutputInternal(xmlSaveCtxtPtr ctxt, xmlNodePtr cur); |
500 void xmlNsListDumpOutput(xmlOutputBufferPtr buf, xmlNsPtr cur); | 596 void xmlNsListDumpOutput(xmlOutputBufferPtr buf, xmlNsPtr cur); |
501 static int xmlDocContentDumpOutput(xmlSaveCtxtPtr ctxt, xmlDocPtr cur); | 597 static int xmlDocContentDumpOutput(xmlSaveCtxtPtr ctxt, xmlDocPtr cur); |
502 | 598 |
503 /** | 599 /** |
| 600 * xmlOutputBufferWriteWSNonSig: |
| 601 * @ctxt: The save context |
| 602 * @extra: Number of extra indents to apply to ctxt->level |
| 603 * |
| 604 * Write out formatting for non-significant whitespace output. |
| 605 */ |
| 606 static void |
| 607 xmlOutputBufferWriteWSNonSig(xmlSaveCtxtPtr ctxt, int extra) |
| 608 { |
| 609 int i; |
| 610 if ((ctxt == NULL) || (ctxt->buf == NULL)) |
| 611 return; |
| 612 xmlOutputBufferWrite(ctxt->buf, 1, "\n"); |
| 613 for (i = 0; i < (ctxt->level + extra); i += ctxt->indent_nr) { |
| 614 xmlOutputBufferWrite(ctxt->buf, ctxt->indent_size * |
| 615 ((ctxt->level + extra - i) > ctxt->indent_nr ? |
| 616 ctxt->indent_nr : (ctxt->level + extra - i)), |
| 617 ctxt->indent); |
| 618 } |
| 619 } |
| 620 |
| 621 /** |
504 * xmlNsDumpOutput: | 622 * xmlNsDumpOutput: |
505 * @buf: the XML buffer output | 623 * @buf: the XML buffer output |
506 * @cur: a namespace | 624 * @cur: a namespace |
| 625 * @ctxt: the output save context. Optional. |
507 * | 626 * |
508 * Dump a local Namespace definition. | 627 * Dump a local Namespace definition. |
509 * Should be called in the context of attributes dumps. | 628 * Should be called in the context of attributes dumps. |
| 629 * If @ctxt is supplied, @buf should be its buffer. |
510 */ | 630 */ |
511 static void | 631 static void |
512 xmlNsDumpOutput(xmlOutputBufferPtr buf, xmlNsPtr cur) { | 632 xmlNsDumpOutput(xmlOutputBufferPtr buf, xmlNsPtr cur, xmlSaveCtxtPtr ctxt) { |
513 if ((cur == NULL) || (buf == NULL)) return; | 633 if ((cur == NULL) || (buf == NULL)) return; |
514 if ((cur->type == XML_LOCAL_NAMESPACE) && (cur->href != NULL)) { | 634 if ((cur->type == XML_LOCAL_NAMESPACE) && (cur->href != NULL)) { |
515 if (xmlStrEqual(cur->prefix, BAD_CAST "xml")) | 635 if (xmlStrEqual(cur->prefix, BAD_CAST "xml")) |
516 return; | 636 return; |
517 | 637 |
| 638 if (ctxt != NULL && ctxt->format == 2) |
| 639 xmlOutputBufferWriteWSNonSig(ctxt, 2); |
| 640 else |
| 641 xmlOutputBufferWrite(buf, 1, " "); |
| 642 |
518 /* Within the context of an element attributes */ | 643 /* Within the context of an element attributes */ |
519 if (cur->prefix != NULL) { | 644 if (cur->prefix != NULL) { |
520 » xmlOutputBufferWrite(buf, 7, " xmlns:"); | 645 » xmlOutputBufferWrite(buf, 6, "xmlns:"); |
521 xmlOutputBufferWriteString(buf, (const char *)cur->prefix); | 646 xmlOutputBufferWriteString(buf, (const char *)cur->prefix); |
522 } else | 647 } else |
523 » xmlOutputBufferWrite(buf, 6, " xmlns"); | 648 » xmlOutputBufferWrite(buf, 5, "xmlns"); |
524 xmlOutputBufferWrite(buf, 1, "="); | 649 xmlOutputBufferWrite(buf, 1, "="); |
525 » xmlBufferWriteQuotedString(buf->buffer, cur->href); | 650 » xmlBufWriteQuotedString(buf->buffer, cur->href); |
526 } | 651 } |
527 } | 652 } |
528 | 653 |
| 654 /** |
| 655 * xmlNsDumpOutputCtxt |
| 656 * @ctxt: the save context |
| 657 * @cur: a namespace |
| 658 * |
| 659 * Dump a local Namespace definition to a save context. |
| 660 * Should be called in the context of attribute dumps. |
| 661 */ |
| 662 static void |
| 663 xmlNsDumpOutputCtxt(xmlSaveCtxtPtr ctxt, xmlNsPtr cur) { |
| 664 xmlNsDumpOutput(ctxt->buf, cur, ctxt); |
| 665 } |
| 666 |
| 667 /** |
| 668 * xmlNsListDumpOutputCtxt |
| 669 * @ctxt: the save context |
| 670 * @cur: the first namespace |
| 671 * |
| 672 * Dump a list of local namespace definitions to a save context. |
| 673 * Should be called in the context of attribute dumps. |
| 674 */ |
| 675 static void |
| 676 xmlNsListDumpOutputCtxt(xmlSaveCtxtPtr ctxt, xmlNsPtr cur) { |
| 677 while (cur != NULL) { |
| 678 xmlNsDumpOutput(ctxt->buf, cur, ctxt); |
| 679 cur = cur->next; |
| 680 } |
| 681 } |
| 682 |
529 /** | 683 /** |
530 * xmlNsListDumpOutput: | 684 * xmlNsListDumpOutput: |
531 * @buf: the XML buffer output | 685 * @buf: the XML buffer output |
532 * @cur: the first namespace | 686 * @cur: the first namespace |
533 * | 687 * |
534 * Dump a list of local Namespace definitions. | 688 * Dump a list of local Namespace definitions. |
535 * Should be called in the context of attributes dumps. | 689 * Should be called in the context of attributes dumps. |
536 */ | 690 */ |
537 void | 691 void |
538 xmlNsListDumpOutput(xmlOutputBufferPtr buf, xmlNsPtr cur) { | 692 xmlNsListDumpOutput(xmlOutputBufferPtr buf, xmlNsPtr cur) { |
539 while (cur != NULL) { | 693 while (cur != NULL) { |
540 xmlNsDumpOutput(buf, cur); | 694 xmlNsDumpOutput(buf, cur, NULL); |
541 cur = cur->next; | 695 cur = cur->next; |
542 } | 696 } |
543 } | 697 } |
544 | 698 |
545 /** | 699 /** |
546 * xmlDtdDumpOutput: | 700 * xmlDtdDumpOutput: |
547 * @buf: the XML buffer output | 701 * @buf: the XML buffer output |
548 * @dtd: the pointer to the DTD | 702 * @dtd: the pointer to the DTD |
549 * | 703 * |
550 * Dump the XML document DTD, if any. | 704 * Dump the XML document DTD, if any. |
551 */ | 705 */ |
552 static void | 706 static void |
553 xmlDtdDumpOutput(xmlSaveCtxtPtr ctxt, xmlDtdPtr dtd) { | 707 xmlDtdDumpOutput(xmlSaveCtxtPtr ctxt, xmlDtdPtr dtd) { |
554 xmlOutputBufferPtr buf; | 708 xmlOutputBufferPtr buf; |
555 int format, level; | 709 int format, level; |
556 xmlDocPtr doc; | 710 xmlDocPtr doc; |
557 | 711 |
558 if (dtd == NULL) return; | 712 if (dtd == NULL) return; |
559 if ((ctxt == NULL) || (ctxt->buf == NULL)) | 713 if ((ctxt == NULL) || (ctxt->buf == NULL)) |
560 return; | 714 return; |
561 buf = ctxt->buf; | 715 buf = ctxt->buf; |
562 xmlOutputBufferWrite(buf, 10, "<!DOCTYPE "); | 716 xmlOutputBufferWrite(buf, 10, "<!DOCTYPE "); |
563 xmlOutputBufferWriteString(buf, (const char *)dtd->name); | 717 xmlOutputBufferWriteString(buf, (const char *)dtd->name); |
564 if (dtd->ExternalID != NULL) { | 718 if (dtd->ExternalID != NULL) { |
565 xmlOutputBufferWrite(buf, 8, " PUBLIC "); | 719 xmlOutputBufferWrite(buf, 8, " PUBLIC "); |
566 » xmlBufferWriteQuotedString(buf->buffer, dtd->ExternalID); | 720 » xmlBufWriteQuotedString(buf->buffer, dtd->ExternalID); |
567 xmlOutputBufferWrite(buf, 1, " "); | 721 xmlOutputBufferWrite(buf, 1, " "); |
568 » xmlBufferWriteQuotedString(buf->buffer, dtd->SystemID); | 722 » xmlBufWriteQuotedString(buf->buffer, dtd->SystemID); |
569 } else if (dtd->SystemID != NULL) { | 723 } else if (dtd->SystemID != NULL) { |
570 xmlOutputBufferWrite(buf, 8, " SYSTEM "); | 724 xmlOutputBufferWrite(buf, 8, " SYSTEM "); |
571 » xmlBufferWriteQuotedString(buf->buffer, dtd->SystemID); | 725 » xmlBufWriteQuotedString(buf->buffer, dtd->SystemID); |
572 } | 726 } |
573 if ((dtd->entities == NULL) && (dtd->elements == NULL) && | 727 if ((dtd->entities == NULL) && (dtd->elements == NULL) && |
574 (dtd->attributes == NULL) && (dtd->notations == NULL) && | 728 (dtd->attributes == NULL) && (dtd->notations == NULL) && |
575 (dtd->pentities == NULL)) { | 729 (dtd->pentities == NULL)) { |
576 xmlOutputBufferWrite(buf, 1, ">"); | 730 xmlOutputBufferWrite(buf, 1, ">"); |
577 return; | 731 return; |
578 } | 732 } |
579 xmlOutputBufferWrite(buf, 3, " [\n"); | 733 xmlOutputBufferWrite(buf, 3, " [\n"); |
580 /* | 734 /* |
581 * Dump the notations first they are not in the DTD children list | 735 * Dump the notations first they are not in the DTD children list |
582 * Do this only on a standalone DTD or on the internal subset though. | 736 * Do this only on a standalone DTD or on the internal subset though. |
583 */ | 737 */ |
584 if ((dtd->notations != NULL) && ((dtd->doc == NULL) || | 738 if ((dtd->notations != NULL) && ((dtd->doc == NULL) || |
585 (dtd->doc->intSubset == dtd))) { | 739 (dtd->doc->intSubset == dtd))) { |
586 xmlDumpNotationTable(buf->buffer, (xmlNotationTablePtr) dtd->notations); | 740 xmlBufDumpNotationTable(buf->buffer, |
| 741 (xmlNotationTablePtr) dtd->notations); |
587 } | 742 } |
588 format = ctxt->format; | 743 format = ctxt->format; |
589 level = ctxt->level; | 744 level = ctxt->level; |
590 doc = ctxt->doc; | 745 doc = ctxt->doc; |
591 ctxt->format = 0; | 746 ctxt->format = 0; |
592 ctxt->level = -1; | 747 ctxt->level = -1; |
593 ctxt->doc = dtd->doc; | 748 ctxt->doc = dtd->doc; |
594 xmlNodeListDumpOutput(ctxt, dtd->children); | 749 xmlNodeListDumpOutput(ctxt, dtd->children); |
595 ctxt->format = format; | 750 ctxt->format = format; |
596 ctxt->level = level; | 751 ctxt->level = level; |
597 ctxt->doc = doc; | 752 ctxt->doc = doc; |
598 xmlOutputBufferWrite(buf, 2, "]>"); | 753 xmlOutputBufferWrite(buf, 2, "]>"); |
599 } | 754 } |
600 | 755 |
601 /** | 756 /** |
602 * xmlAttrDumpOutput: | 757 * xmlAttrDumpOutput: |
603 * @buf: the XML buffer output | 758 * @buf: the XML buffer output |
604 * @cur: the attribute pointer | 759 * @cur: the attribute pointer |
605 * | 760 * |
606 * Dump an XML attribute | 761 * Dump an XML attribute |
607 */ | 762 */ |
608 static void | 763 static void |
609 xmlAttrDumpOutput(xmlSaveCtxtPtr ctxt, xmlAttrPtr cur) { | 764 xmlAttrDumpOutput(xmlSaveCtxtPtr ctxt, xmlAttrPtr cur) { |
610 xmlOutputBufferPtr buf; | 765 xmlOutputBufferPtr buf; |
611 | 766 |
612 if (cur == NULL) return; | 767 if (cur == NULL) return; |
613 buf = ctxt->buf; | 768 buf = ctxt->buf; |
614 if (buf == NULL) return; | 769 if (buf == NULL) return; |
615 xmlOutputBufferWrite(buf, 1, " "); | 770 if (ctxt->format == 2) |
| 771 xmlOutputBufferWriteWSNonSig(ctxt, 2); |
| 772 else |
| 773 xmlOutputBufferWrite(buf, 1, " "); |
616 if ((cur->ns != NULL) && (cur->ns->prefix != NULL)) { | 774 if ((cur->ns != NULL) && (cur->ns->prefix != NULL)) { |
617 xmlOutputBufferWriteString(buf, (const char *)cur->ns->prefix); | 775 xmlOutputBufferWriteString(buf, (const char *)cur->ns->prefix); |
618 xmlOutputBufferWrite(buf, 1, ":"); | 776 xmlOutputBufferWrite(buf, 1, ":"); |
619 } | 777 } |
620 xmlOutputBufferWriteString(buf, (const char *)cur->name); | 778 xmlOutputBufferWriteString(buf, (const char *)cur->name); |
621 xmlOutputBufferWrite(buf, 2, "=\""); | 779 xmlOutputBufferWrite(buf, 2, "=\""); |
622 xmlAttrSerializeContent(buf, cur); | 780 xmlAttrSerializeContent(buf, cur); |
623 xmlOutputBufferWrite(buf, 1, "\""); | 781 xmlOutputBufferWrite(buf, 1, "\""); |
624 } | 782 } |
625 | 783 |
(...skipping 23 matching lines...) Expand all Loading... |
649 * | 807 * |
650 * Dump an XML node list, recursive behaviour, children are printed too. | 808 * Dump an XML node list, recursive behaviour, children are printed too. |
651 */ | 809 */ |
652 static void | 810 static void |
653 xmlNodeListDumpOutput(xmlSaveCtxtPtr ctxt, xmlNodePtr cur) { | 811 xmlNodeListDumpOutput(xmlSaveCtxtPtr ctxt, xmlNodePtr cur) { |
654 xmlOutputBufferPtr buf; | 812 xmlOutputBufferPtr buf; |
655 | 813 |
656 if (cur == NULL) return; | 814 if (cur == NULL) return; |
657 buf = ctxt->buf; | 815 buf = ctxt->buf; |
658 while (cur != NULL) { | 816 while (cur != NULL) { |
659 » if ((ctxt->format) && (xmlIndentTreeOutput) && | 817 » if ((ctxt->format == 1) && (xmlIndentTreeOutput) && |
660 ((cur->type == XML_ELEMENT_NODE) || | 818 ((cur->type == XML_ELEMENT_NODE) || |
661 (cur->type == XML_COMMENT_NODE) || | 819 (cur->type == XML_COMMENT_NODE) || |
662 (cur->type == XML_PI_NODE))) | 820 (cur->type == XML_PI_NODE))) |
663 xmlOutputBufferWrite(buf, ctxt->indent_size * | 821 xmlOutputBufferWrite(buf, ctxt->indent_size * |
664 » (ctxt->level > ctxt->indent_nr ? | 822 » (ctxt->level > ctxt->indent_nr ? |
665 ctxt->indent_nr : ctxt->level), | 823 ctxt->indent_nr : ctxt->level), |
666 ctxt->indent); | 824 ctxt->indent); |
667 xmlNodeDumpOutputInternal(ctxt, cur); | 825 xmlNodeDumpOutputInternal(ctxt, cur); |
668 » if (ctxt->format) { | 826 » if (ctxt->format == 1) { |
669 xmlOutputBufferWrite(buf, 1, "\n"); | 827 xmlOutputBufferWrite(buf, 1, "\n"); |
670 } | 828 } |
671 cur = cur->next; | 829 cur = cur->next; |
672 } | 830 } |
673 } | 831 } |
674 | 832 |
675 #ifdef LIBXML_HTML_ENABLED | 833 #ifdef LIBXML_HTML_ENABLED |
676 /** | 834 /** |
677 * xmlNodeDumpOutputInternal: | 835 * xmlNodeDumpOutputInternal: |
678 * @cur: the current node | 836 * @cur: the current node |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
771 #endif | 929 #endif |
772 if (cur->type == XML_DTD_NODE) { | 930 if (cur->type == XML_DTD_NODE) { |
773 xmlDtdDumpOutput(ctxt, (xmlDtdPtr) cur); | 931 xmlDtdDumpOutput(ctxt, (xmlDtdPtr) cur); |
774 return; | 932 return; |
775 } | 933 } |
776 if (cur->type == XML_DOCUMENT_FRAG_NODE) { | 934 if (cur->type == XML_DOCUMENT_FRAG_NODE) { |
777 xmlNodeListDumpOutput(ctxt, cur->children); | 935 xmlNodeListDumpOutput(ctxt, cur->children); |
778 return; | 936 return; |
779 } | 937 } |
780 if (cur->type == XML_ELEMENT_DECL) { | 938 if (cur->type == XML_ELEMENT_DECL) { |
781 xmlDumpElementDecl(buf->buffer, (xmlElementPtr) cur); | 939 xmlBufDumpElementDecl(buf->buffer, (xmlElementPtr) cur); |
782 return; | 940 return; |
783 } | 941 } |
784 if (cur->type == XML_ATTRIBUTE_DECL) { | 942 if (cur->type == XML_ATTRIBUTE_DECL) { |
785 xmlDumpAttributeDecl(buf->buffer, (xmlAttributePtr) cur); | 943 xmlBufDumpAttributeDecl(buf->buffer, (xmlAttributePtr) cur); |
786 return; | 944 return; |
787 } | 945 } |
788 if (cur->type == XML_ENTITY_DECL) { | 946 if (cur->type == XML_ENTITY_DECL) { |
789 xmlDumpEntityDecl(buf->buffer, (xmlEntityPtr) cur); | 947 xmlBufDumpEntityDecl(buf->buffer, (xmlEntityPtr) cur); |
790 return; | 948 return; |
791 } | 949 } |
792 if (cur->type == XML_TEXT_NODE) { | 950 if (cur->type == XML_TEXT_NODE) { |
793 if (cur->content != NULL) { | 951 if (cur->content != NULL) { |
794 if (cur->name != xmlStringTextNoenc) { | 952 if (cur->name != xmlStringTextNoenc) { |
795 xmlOutputBufferWriteEscape(buf, cur->content, ctxt->escape); | 953 xmlOutputBufferWriteEscape(buf, cur->content, ctxt->escape); |
796 } else { | 954 } else { |
797 /* | 955 /* |
798 * Disable escaping, needed for XSLT | 956 * Disable escaping, needed for XSLT |
799 */ | 957 */ |
800 xmlOutputBufferWriteString(buf, (const char *) cur->content); | 958 xmlOutputBufferWriteString(buf, (const char *) cur->content); |
801 } | 959 } |
802 } | 960 } |
803 | 961 |
804 return; | 962 return; |
805 } | 963 } |
806 if (cur->type == XML_PI_NODE) { | 964 if (cur->type == XML_PI_NODE) { |
807 if (cur->content != NULL) { | 965 if (cur->content != NULL) { |
808 xmlOutputBufferWrite(buf, 2, "<?"); | 966 xmlOutputBufferWrite(buf, 2, "<?"); |
809 xmlOutputBufferWriteString(buf, (const char *)cur->name); | 967 xmlOutputBufferWriteString(buf, (const char *)cur->name); |
810 if (cur->content != NULL) { | 968 if (cur->content != NULL) { |
811 » » xmlOutputBufferWrite(buf, 1, " "); | 969 » if (ctxt->format == 2) |
| 970 » xmlOutputBufferWriteWSNonSig(ctxt, 0); |
| 971 » else |
| 972 » xmlOutputBufferWrite(buf, 1, " "); |
812 xmlOutputBufferWriteString(buf, (const char *)cur->content); | 973 xmlOutputBufferWriteString(buf, (const char *)cur->content); |
813 } | 974 } |
814 xmlOutputBufferWrite(buf, 2, "?>"); | 975 xmlOutputBufferWrite(buf, 2, "?>"); |
815 } else { | 976 } else { |
816 xmlOutputBufferWrite(buf, 2, "<?"); | 977 xmlOutputBufferWrite(buf, 2, "<?"); |
817 xmlOutputBufferWriteString(buf, (const char *)cur->name); | 978 xmlOutputBufferWriteString(buf, (const char *)cur->name); |
| 979 if (ctxt->format == 2) |
| 980 xmlOutputBufferWriteWSNonSig(ctxt, 0); |
818 xmlOutputBufferWrite(buf, 2, "?>"); | 981 xmlOutputBufferWrite(buf, 2, "?>"); |
819 } | 982 } |
820 return; | 983 return; |
821 } | 984 } |
822 if (cur->type == XML_COMMENT_NODE) { | 985 if (cur->type == XML_COMMENT_NODE) { |
823 if (cur->content != NULL) { | 986 if (cur->content != NULL) { |
824 xmlOutputBufferWrite(buf, 4, "<!--"); | 987 xmlOutputBufferWrite(buf, 4, "<!--"); |
825 xmlOutputBufferWriteString(buf, (const char *)cur->content); | 988 xmlOutputBufferWriteString(buf, (const char *)cur->content); |
826 xmlOutputBufferWrite(buf, 3, "-->"); | 989 xmlOutputBufferWrite(buf, 3, "-->"); |
827 } | 990 } |
(...skipping 27 matching lines...) Expand all Loading... |
855 xmlOutputBufferWrite(buf, 3, "]]>"); | 1018 xmlOutputBufferWrite(buf, 3, "]]>"); |
856 } | 1019 } |
857 } | 1020 } |
858 return; | 1021 return; |
859 } | 1022 } |
860 if (cur->type == XML_ATTRIBUTE_NODE) { | 1023 if (cur->type == XML_ATTRIBUTE_NODE) { |
861 xmlAttrDumpOutput(ctxt, (xmlAttrPtr) cur); | 1024 xmlAttrDumpOutput(ctxt, (xmlAttrPtr) cur); |
862 return; | 1025 return; |
863 } | 1026 } |
864 if (cur->type == XML_NAMESPACE_DECL) { | 1027 if (cur->type == XML_NAMESPACE_DECL) { |
865 » xmlNsDumpOutput(buf, (xmlNsPtr) cur); | 1028 » xmlNsDumpOutputCtxt(ctxt, (xmlNsPtr) cur); |
866 return; | 1029 return; |
867 } | 1030 } |
868 | 1031 |
869 format = ctxt->format; | 1032 format = ctxt->format; |
870 if (format == 1) { | 1033 if (format == 1) { |
871 tmp = cur->children; | 1034 tmp = cur->children; |
872 while (tmp != NULL) { | 1035 while (tmp != NULL) { |
873 if ((tmp->type == XML_TEXT_NODE) || | 1036 if ((tmp->type == XML_TEXT_NODE) || |
874 (tmp->type == XML_CDATA_SECTION_NODE) || | 1037 (tmp->type == XML_CDATA_SECTION_NODE) || |
875 (tmp->type == XML_ENTITY_REF_NODE)) { | 1038 (tmp->type == XML_ENTITY_REF_NODE)) { |
876 ctxt->format = 0; | 1039 ctxt->format = 0; |
877 break; | 1040 break; |
878 } | 1041 } |
879 tmp = tmp->next; | 1042 tmp = tmp->next; |
880 } | 1043 } |
881 } | 1044 } |
882 xmlOutputBufferWrite(buf, 1, "<"); | 1045 xmlOutputBufferWrite(buf, 1, "<"); |
883 if ((cur->ns != NULL) && (cur->ns->prefix != NULL)) { | 1046 if ((cur->ns != NULL) && (cur->ns->prefix != NULL)) { |
884 xmlOutputBufferWriteString(buf, (const char *)cur->ns->prefix); | 1047 xmlOutputBufferWriteString(buf, (const char *)cur->ns->prefix); |
885 xmlOutputBufferWrite(buf, 1, ":"); | 1048 xmlOutputBufferWrite(buf, 1, ":"); |
886 } | 1049 } |
887 | 1050 |
888 xmlOutputBufferWriteString(buf, (const char *)cur->name); | 1051 xmlOutputBufferWriteString(buf, (const char *)cur->name); |
889 if (cur->nsDef) | 1052 if (cur->nsDef) |
890 xmlNsListDumpOutput(buf, cur->nsDef); | 1053 xmlNsListDumpOutputCtxt(ctxt, cur->nsDef); |
891 if (cur->properties != NULL) | 1054 if (cur->properties != NULL) |
892 xmlAttrListDumpOutput(ctxt, cur->properties); | 1055 xmlAttrListDumpOutput(ctxt, cur->properties); |
893 | 1056 |
894 if (((cur->type == XML_ELEMENT_NODE) || (cur->content == NULL)) && | 1057 if (((cur->type == XML_ELEMENT_NODE) || (cur->content == NULL)) && |
895 (cur->children == NULL) && ((ctxt->options & XML_SAVE_NO_EMPTY) == 0)) { | 1058 (cur->children == NULL) && ((ctxt->options & XML_SAVE_NO_EMPTY) == 0)) { |
| 1059 if (ctxt->format == 2) |
| 1060 xmlOutputBufferWriteWSNonSig(ctxt, 0); |
896 xmlOutputBufferWrite(buf, 2, "/>"); | 1061 xmlOutputBufferWrite(buf, 2, "/>"); |
897 ctxt->format = format; | 1062 ctxt->format = format; |
898 return; | 1063 return; |
899 } | 1064 } |
| 1065 if (ctxt->format == 2) |
| 1066 xmlOutputBufferWriteWSNonSig(ctxt, 1); |
900 xmlOutputBufferWrite(buf, 1, ">"); | 1067 xmlOutputBufferWrite(buf, 1, ">"); |
901 if ((cur->type != XML_ELEMENT_NODE) && (cur->content != NULL)) { | 1068 if ((cur->type != XML_ELEMENT_NODE) && (cur->content != NULL)) { |
902 xmlOutputBufferWriteEscape(buf, cur->content, ctxt->escape); | 1069 xmlOutputBufferWriteEscape(buf, cur->content, ctxt->escape); |
903 } | 1070 } |
904 if (cur->children != NULL) { | 1071 if (cur->children != NULL) { |
905 » if (ctxt->format) xmlOutputBufferWrite(buf, 1, "\n"); | 1072 » if (ctxt->format == 1) xmlOutputBufferWrite(buf, 1, "\n"); |
906 if (ctxt->level >= 0) ctxt->level++; | 1073 if (ctxt->level >= 0) ctxt->level++; |
907 xmlNodeListDumpOutput(ctxt, cur->children); | 1074 xmlNodeListDumpOutput(ctxt, cur->children); |
908 if (ctxt->level > 0) ctxt->level--; | 1075 if (ctxt->level > 0) ctxt->level--; |
909 » if ((xmlIndentTreeOutput) && (ctxt->format)) | 1076 » if ((xmlIndentTreeOutput) && (ctxt->format == 1)) |
910 xmlOutputBufferWrite(buf, ctxt->indent_size * | 1077 xmlOutputBufferWrite(buf, ctxt->indent_size * |
911 » (ctxt->level > ctxt->indent_nr ? | 1078 » (ctxt->level > ctxt->indent_nr ? |
912 ctxt->indent_nr : ctxt->level), | 1079 ctxt->indent_nr : ctxt->level), |
913 ctxt->indent); | 1080 ctxt->indent); |
914 } | 1081 } |
915 xmlOutputBufferWrite(buf, 2, "</"); | 1082 xmlOutputBufferWrite(buf, 2, "</"); |
916 if ((cur->ns != NULL) && (cur->ns->prefix != NULL)) { | 1083 if ((cur->ns != NULL) && (cur->ns->prefix != NULL)) { |
917 xmlOutputBufferWriteString(buf, (const char *)cur->ns->prefix); | 1084 xmlOutputBufferWriteString(buf, (const char *)cur->ns->prefix); |
918 xmlOutputBufferWrite(buf, 1, ":"); | 1085 xmlOutputBufferWrite(buf, 1, ":"); |
919 } | 1086 } |
920 | 1087 |
921 xmlOutputBufferWriteString(buf, (const char *)cur->name); | 1088 xmlOutputBufferWriteString(buf, (const char *)cur->name); |
| 1089 if (ctxt->format == 2) |
| 1090 xmlOutputBufferWriteWSNonSig(ctxt, 0); |
922 xmlOutputBufferWrite(buf, 1, ">"); | 1091 xmlOutputBufferWrite(buf, 1, ">"); |
923 ctxt->format = format; | 1092 ctxt->format = format; |
924 } | 1093 } |
925 | 1094 |
926 /** | 1095 /** |
927 * xmlDocContentDumpOutput: | 1096 * xmlDocContentDumpOutput: |
928 * @cur: the document | 1097 * @cur: the document |
929 * | 1098 * |
930 * Dump an XML document. | 1099 * Dump an XML document. |
931 */ | 1100 */ |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1015 if (ctxt->escapeAttr == xmlEscapeEntities) | 1184 if (ctxt->escapeAttr == xmlEscapeEntities) |
1016 ctxt->escapeAttr = NULL; | 1185 ctxt->escapeAttr = NULL; |
1017 } | 1186 } |
1018 | 1187 |
1019 | 1188 |
1020 /* | 1189 /* |
1021 * Save the XML declaration | 1190 * Save the XML declaration |
1022 */ | 1191 */ |
1023 if ((ctxt->options & XML_SAVE_NO_DECL) == 0) { | 1192 if ((ctxt->options & XML_SAVE_NO_DECL) == 0) { |
1024 xmlOutputBufferWrite(buf, 14, "<?xml version="); | 1193 xmlOutputBufferWrite(buf, 14, "<?xml version="); |
1025 » if (cur->version != NULL) | 1194 » if (cur->version != NULL) |
1026 » » xmlBufferWriteQuotedString(buf->buffer, cur->version); | 1195 » » xmlBufWriteQuotedString(buf->buffer, cur->version); |
1027 else | 1196 else |
1028 xmlOutputBufferWrite(buf, 5, "\"1.0\""); | 1197 xmlOutputBufferWrite(buf, 5, "\"1.0\""); |
1029 if (encoding != NULL) { | 1198 if (encoding != NULL) { |
1030 xmlOutputBufferWrite(buf, 10, " encoding="); | 1199 xmlOutputBufferWrite(buf, 10, " encoding="); |
1031 » » xmlBufferWriteQuotedString(buf->buffer, (xmlChar *) encoding); | 1200 » » xmlBufWriteQuotedString(buf->buffer, (xmlChar *) encoding); |
1032 } | 1201 } |
1033 switch (cur->standalone) { | 1202 switch (cur->standalone) { |
1034 case 0: | 1203 case 0: |
1035 xmlOutputBufferWrite(buf, 16, " standalone=\"no\""); | 1204 xmlOutputBufferWrite(buf, 16, " standalone=\"no\""); |
1036 break; | 1205 break; |
1037 case 1: | 1206 case 1: |
1038 xmlOutputBufferWrite(buf, 17, " standalone=\"yes\""); | 1207 xmlOutputBufferWrite(buf, 17, " standalone=\"yes\""); |
1039 break; | 1208 break; |
1040 } | 1209 } |
1041 xmlOutputBufferWrite(buf, 3, "?>\n"); | 1210 xmlOutputBufferWrite(buf, 3, "?>\n"); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1179 else | 1348 else |
1180 if ((cur->ns == NULL) && (xmlStrEqual(cur->name, BAD_CAST "name"))) | 1349 if ((cur->ns == NULL) && (xmlStrEqual(cur->name, BAD_CAST "name"))) |
1181 name = cur; | 1350 name = cur; |
1182 else | 1351 else |
1183 if ((cur->ns == NULL) && (xmlStrEqual(cur->name, BAD_CAST "lang"))) | 1352 if ((cur->ns == NULL) && (xmlStrEqual(cur->name, BAD_CAST "lang"))) |
1184 lang = cur; | 1353 lang = cur; |
1185 else | 1354 else |
1186 if ((cur->ns != NULL) && (xmlStrEqual(cur->name, BAD_CAST "lang")) && | 1355 if ((cur->ns != NULL) && (xmlStrEqual(cur->name, BAD_CAST "lang")) && |
1187 (xmlStrEqual(cur->ns->prefix, BAD_CAST "xml"))) | 1356 (xmlStrEqual(cur->ns->prefix, BAD_CAST "xml"))) |
1188 xml_lang = cur; | 1357 xml_lang = cur; |
1189 » else if ((cur->ns == NULL) && | 1358 » else if ((cur->ns == NULL) && |
1190 ((cur->children == NULL) || | 1359 ((cur->children == NULL) || |
1191 (cur->children->content == NULL) || | 1360 (cur->children->content == NULL) || |
1192 (cur->children->content[0] == 0)) && | 1361 (cur->children->content[0] == 0)) && |
1193 (htmlIsBooleanAttr(cur->name))) { | 1362 (htmlIsBooleanAttr(cur->name))) { |
1194 if (cur->children != NULL) | 1363 if (cur->children != NULL) |
1195 xmlFreeNode(cur->children); | 1364 xmlFreeNode(cur->children); |
1196 cur->children = xmlNewText(cur->name); | 1365 cur->children = xmlNewText(cur->name); |
1197 if (cur->children != NULL) | 1366 if (cur->children != NULL) |
1198 cur->children->parent = (xmlNodePtr) cur; | 1367 cur->children->parent = (xmlNodePtr) cur; |
1199 } | 1368 } |
(...skipping 19 matching lines...) Expand all Loading... |
1219 xmlOutputBufferWrite(buf, 1, "\""); | 1388 xmlOutputBufferWrite(buf, 1, "\""); |
1220 } | 1389 } |
1221 } | 1390 } |
1222 /* | 1391 /* |
1223 * C.7. | 1392 * C.7. |
1224 */ | 1393 */ |
1225 if ((lang != NULL) && (xml_lang == NULL)) { | 1394 if ((lang != NULL) && (xml_lang == NULL)) { |
1226 xmlOutputBufferWrite(buf, 11, " xml:lang=\""); | 1395 xmlOutputBufferWrite(buf, 11, " xml:lang=\""); |
1227 xmlAttrSerializeContent(buf, lang); | 1396 xmlAttrSerializeContent(buf, lang); |
1228 xmlOutputBufferWrite(buf, 1, "\""); | 1397 xmlOutputBufferWrite(buf, 1, "\""); |
1229 } else | 1398 } else |
1230 if ((xml_lang != NULL) && (lang == NULL)) { | 1399 if ((xml_lang != NULL) && (lang == NULL)) { |
1231 xmlOutputBufferWrite(buf, 7, " lang=\""); | 1400 xmlOutputBufferWrite(buf, 7, " lang=\""); |
1232 xmlAttrSerializeContent(buf, xml_lang); | 1401 xmlAttrSerializeContent(buf, xml_lang); |
1233 xmlOutputBufferWrite(buf, 1, "\""); | 1402 xmlOutputBufferWrite(buf, 1, "\""); |
1234 } | 1403 } |
1235 } | 1404 } |
1236 | 1405 |
1237 /** | 1406 /** |
1238 * xhtmlNodeListDumpOutput: | 1407 * xhtmlNodeListDumpOutput: |
1239 * @buf: the XML buffer output | 1408 * @buf: the XML buffer output |
1240 * @doc: the XHTML document | 1409 * @doc: the XHTML document |
1241 * @cur: the first node | 1410 * @cur: the first node |
1242 * @level: the imbrication level for indenting | 1411 * @level: the imbrication level for indenting |
1243 * @format: is formatting allowed | 1412 * @format: is formatting allowed |
1244 * @encoding: an optional encoding string | 1413 * @encoding: an optional encoding string |
1245 * | 1414 * |
1246 * Dump an XML node list, recursive behaviour, children are printed too. | 1415 * Dump an XML node list, recursive behaviour, children are printed too. |
1247 * Note that @format = 1 provide node indenting only if xmlIndentTreeOutput = 1 | 1416 * Note that @format = 1 provide node indenting only if xmlIndentTreeOutput = 1 |
1248 * or xmlKeepBlanksDefault(0) was called | 1417 * or xmlKeepBlanksDefault(0) was called |
1249 */ | 1418 */ |
1250 static void | 1419 static void |
1251 xhtmlNodeListDumpOutput(xmlSaveCtxtPtr ctxt, xmlNodePtr cur) { | 1420 xhtmlNodeListDumpOutput(xmlSaveCtxtPtr ctxt, xmlNodePtr cur) { |
1252 xmlOutputBufferPtr buf; | 1421 xmlOutputBufferPtr buf; |
1253 | 1422 |
1254 if (cur == NULL) return; | 1423 if (cur == NULL) return; |
1255 buf = ctxt->buf; | 1424 buf = ctxt->buf; |
1256 while (cur != NULL) { | 1425 while (cur != NULL) { |
1257 » if ((ctxt->format) && (xmlIndentTreeOutput) && | 1426 » if ((ctxt->format == 1) && (xmlIndentTreeOutput) && |
1258 (cur->type == XML_ELEMENT_NODE)) | 1427 (cur->type == XML_ELEMENT_NODE)) |
1259 xmlOutputBufferWrite(buf, ctxt->indent_size * | 1428 xmlOutputBufferWrite(buf, ctxt->indent_size * |
1260 » (ctxt->level > ctxt->indent_nr ? | 1429 » (ctxt->level > ctxt->indent_nr ? |
1261 ctxt->indent_nr : ctxt->level), | 1430 ctxt->indent_nr : ctxt->level), |
1262 ctxt->indent); | 1431 ctxt->indent); |
1263 xhtmlNodeDumpOutput(ctxt, cur); | 1432 xhtmlNodeDumpOutput(ctxt, cur); |
1264 » if (ctxt->format) { | 1433 » if (ctxt->format == 1) { |
1265 xmlOutputBufferWrite(buf, 1, "\n"); | 1434 xmlOutputBufferWrite(buf, 1, "\n"); |
1266 } | 1435 } |
1267 cur = cur->next; | 1436 cur = cur->next; |
1268 } | 1437 } |
1269 } | 1438 } |
1270 | 1439 |
1271 /** | 1440 /** |
1272 * xhtmlNodeDumpOutput: | 1441 * xhtmlNodeDumpOutput: |
1273 * @buf: the XML buffer output | 1442 * @buf: the XML buffer output |
1274 * @doc: the XHTML document | 1443 * @doc: the XHTML document |
(...skipping 14 matching lines...) Expand all Loading... |
1289 if (cur == NULL) return; | 1458 if (cur == NULL) return; |
1290 if ((cur->type == XML_DOCUMENT_NODE) || | 1459 if ((cur->type == XML_DOCUMENT_NODE) || |
1291 (cur->type == XML_HTML_DOCUMENT_NODE)) { | 1460 (cur->type == XML_HTML_DOCUMENT_NODE)) { |
1292 xmlDocContentDumpOutput(ctxt, (xmlDocPtr) cur); | 1461 xmlDocContentDumpOutput(ctxt, (xmlDocPtr) cur); |
1293 return; | 1462 return; |
1294 } | 1463 } |
1295 if (cur->type == XML_XINCLUDE_START) | 1464 if (cur->type == XML_XINCLUDE_START) |
1296 return; | 1465 return; |
1297 if (cur->type == XML_XINCLUDE_END) | 1466 if (cur->type == XML_XINCLUDE_END) |
1298 return; | 1467 return; |
| 1468 if (cur->type == XML_NAMESPACE_DECL) { |
| 1469 xmlNsDumpOutputCtxt(ctxt, (xmlNsPtr) cur); |
| 1470 return; |
| 1471 } |
1299 if (cur->type == XML_DTD_NODE) { | 1472 if (cur->type == XML_DTD_NODE) { |
1300 xmlDtdDumpOutput(ctxt, (xmlDtdPtr) cur); | 1473 xmlDtdDumpOutput(ctxt, (xmlDtdPtr) cur); |
1301 return; | 1474 return; |
1302 } | 1475 } |
1303 if (cur->type == XML_DOCUMENT_FRAG_NODE) { | 1476 if (cur->type == XML_DOCUMENT_FRAG_NODE) { |
1304 xhtmlNodeListDumpOutput(ctxt, cur->children); | 1477 xhtmlNodeListDumpOutput(ctxt, cur->children); |
1305 return; | 1478 return; |
1306 } | 1479 } |
1307 buf = ctxt->buf; | 1480 buf = ctxt->buf; |
1308 if (cur->type == XML_ELEMENT_DECL) { | 1481 if (cur->type == XML_ELEMENT_DECL) { |
1309 xmlDumpElementDecl(buf->buffer, (xmlElementPtr) cur); | 1482 xmlBufDumpElementDecl(buf->buffer, (xmlElementPtr) cur); |
1310 return; | 1483 return; |
1311 } | 1484 } |
1312 if (cur->type == XML_ATTRIBUTE_DECL) { | 1485 if (cur->type == XML_ATTRIBUTE_DECL) { |
1313 xmlDumpAttributeDecl(buf->buffer, (xmlAttributePtr) cur); | 1486 xmlBufDumpAttributeDecl(buf->buffer, (xmlAttributePtr) cur); |
1314 return; | 1487 return; |
1315 } | 1488 } |
1316 if (cur->type == XML_ENTITY_DECL) { | 1489 if (cur->type == XML_ENTITY_DECL) { |
1317 xmlDumpEntityDecl(buf->buffer, (xmlEntityPtr) cur); | 1490 xmlBufDumpEntityDecl(buf->buffer, (xmlEntityPtr) cur); |
1318 return; | 1491 return; |
1319 } | 1492 } |
1320 if (cur->type == XML_TEXT_NODE) { | 1493 if (cur->type == XML_TEXT_NODE) { |
1321 if (cur->content != NULL) { | 1494 if (cur->content != NULL) { |
1322 if ((cur->name == xmlStringText) || | 1495 if ((cur->name == xmlStringText) || |
1323 (cur->name != xmlStringTextNoenc)) { | 1496 (cur->name != xmlStringTextNoenc)) { |
1324 xmlOutputBufferWriteEscape(buf, cur->content, ctxt->escape); | 1497 xmlOutputBufferWriteEscape(buf, cur->content, ctxt->escape); |
1325 } else { | 1498 } else { |
1326 /* | 1499 /* |
1327 * Disable escaping, needed for XSLT | 1500 * Disable escaping, needed for XSLT |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1387 } | 1560 } |
1388 if (cur->type == XML_ATTRIBUTE_NODE) { | 1561 if (cur->type == XML_ATTRIBUTE_NODE) { |
1389 xmlAttrDumpOutput(ctxt, (xmlAttrPtr) cur); | 1562 xmlAttrDumpOutput(ctxt, (xmlAttrPtr) cur); |
1390 return; | 1563 return; |
1391 } | 1564 } |
1392 | 1565 |
1393 format = ctxt->format; | 1566 format = ctxt->format; |
1394 if (format == 1) { | 1567 if (format == 1) { |
1395 tmp = cur->children; | 1568 tmp = cur->children; |
1396 while (tmp != NULL) { | 1569 while (tmp != NULL) { |
1397 » if ((tmp->type == XML_TEXT_NODE) || | 1570 » if ((tmp->type == XML_TEXT_NODE) || |
1398 (tmp->type == XML_ENTITY_REF_NODE)) { | 1571 (tmp->type == XML_ENTITY_REF_NODE)) { |
1399 format = 0; | 1572 format = 0; |
1400 break; | 1573 break; |
1401 } | 1574 } |
1402 tmp = tmp->next; | 1575 tmp = tmp->next; |
1403 } | 1576 } |
1404 } | 1577 } |
1405 xmlOutputBufferWrite(buf, 1, "<"); | 1578 xmlOutputBufferWrite(buf, 1, "<"); |
1406 if ((cur->ns != NULL) && (cur->ns->prefix != NULL)) { | 1579 if ((cur->ns != NULL) && (cur->ns->prefix != NULL)) { |
1407 xmlOutputBufferWriteString(buf, (const char *)cur->ns->prefix); | 1580 xmlOutputBufferWriteString(buf, (const char *)cur->ns->prefix); |
1408 xmlOutputBufferWrite(buf, 1, ":"); | 1581 xmlOutputBufferWrite(buf, 1, ":"); |
1409 } | 1582 } |
1410 | 1583 |
1411 xmlOutputBufferWriteString(buf, (const char *)cur->name); | 1584 xmlOutputBufferWriteString(buf, (const char *)cur->name); |
1412 if (cur->nsDef) | 1585 if (cur->nsDef) |
1413 xmlNsListDumpOutput(buf, cur->nsDef); | 1586 xmlNsListDumpOutputCtxt(ctxt, cur->nsDef); |
1414 if ((xmlStrEqual(cur->name, BAD_CAST "html") && | 1587 if ((xmlStrEqual(cur->name, BAD_CAST "html") && |
1415 (cur->ns == NULL) && (cur->nsDef == NULL))) { | 1588 (cur->ns == NULL) && (cur->nsDef == NULL))) { |
1416 /* | 1589 /* |
1417 * 3.1.1. Strictly Conforming Documents A.3.1.1 3/ | 1590 * 3.1.1. Strictly Conforming Documents A.3.1.1 3/ |
1418 */ | 1591 */ |
1419 xmlOutputBufferWriteString(buf, | 1592 xmlOutputBufferWriteString(buf, |
1420 " xmlns=\"http://www.w3.org/1999/xhtml\""); | 1593 " xmlns=\"http://www.w3.org/1999/xhtml\""); |
1421 } | 1594 } |
1422 if (cur->properties != NULL) | 1595 if (cur->properties != NULL) |
1423 xhtmlAttrListDumpOutput(ctxt, cur->properties); | 1596 xhtmlAttrListDumpOutput(ctxt, cur->properties); |
1424 | 1597 |
1425 » if ((cur->type == XML_ELEMENT_NODE) && | 1598 » if ((cur->type == XML_ELEMENT_NODE) && |
1426 » » (cur->parent != NULL) && | 1599 » » (cur->parent != NULL) && |
1427 » » (cur->parent->parent == (xmlNodePtr) cur->doc) && | 1600 » » (cur->parent->parent == (xmlNodePtr) cur->doc) && |
1428 » » xmlStrEqual(cur->name, BAD_CAST"head") && | 1601 » » xmlStrEqual(cur->name, BAD_CAST"head") && |
1429 xmlStrEqual(cur->parent->name, BAD_CAST"html")) { | 1602 xmlStrEqual(cur->parent->name, BAD_CAST"html")) { |
1430 | 1603 |
1431 tmp = cur->children; | 1604 tmp = cur->children; |
1432 while (tmp != NULL) { | 1605 while (tmp != NULL) { |
1433 if (xmlStrEqual(tmp->name, BAD_CAST"meta")) { | 1606 if (xmlStrEqual(tmp->name, BAD_CAST"meta")) { |
1434 xmlChar *httpequiv; | 1607 xmlChar *httpequiv; |
1435 | 1608 |
1436 httpequiv = xmlGetProp(tmp, BAD_CAST"http-equiv"
); | 1609 httpequiv = xmlGetProp(tmp, BAD_CAST"http-equiv"
); |
1437 if (httpequiv != NULL) { | 1610 if (httpequiv != NULL) { |
1438 if (xmlStrcasecmp(httpequiv, BAD_CAST"Co
ntent-Type") == 0) { | 1611 if (xmlStrcasecmp(httpequiv, BAD_CAST"Co
ntent-Type") == 0) { |
(...skipping 12 matching lines...) Expand all Loading... |
1451 if ((cur->type == XML_ELEMENT_NODE) && (cur->children == NULL)) { | 1624 if ((cur->type == XML_ELEMENT_NODE) && (cur->children == NULL)) { |
1452 if (((cur->ns == NULL) || (cur->ns->prefix == NULL)) && | 1625 if (((cur->ns == NULL) || (cur->ns->prefix == NULL)) && |
1453 ((xhtmlIsEmpty(cur) == 1) && (addmeta == 0))) { | 1626 ((xhtmlIsEmpty(cur) == 1) && (addmeta == 0))) { |
1454 /* | 1627 /* |
1455 * C.2. Empty Elements | 1628 * C.2. Empty Elements |
1456 */ | 1629 */ |
1457 xmlOutputBufferWrite(buf, 3, " />"); | 1630 xmlOutputBufferWrite(buf, 3, " />"); |
1458 } else { | 1631 } else { |
1459 if (addmeta == 1) { | 1632 if (addmeta == 1) { |
1460 xmlOutputBufferWrite(buf, 1, ">"); | 1633 xmlOutputBufferWrite(buf, 1, ">"); |
1461 » » » if (ctxt->format) { | 1634 » » » if (ctxt->format == 1) { |
1462 xmlOutputBufferWrite(buf, 1, "\n"); | 1635 xmlOutputBufferWrite(buf, 1, "\n"); |
1463 if (xmlIndentTreeOutput) | 1636 if (xmlIndentTreeOutput) |
1464 xmlOutputBufferWrite(buf, ctxt->indent_s
ize * | 1637 xmlOutputBufferWrite(buf, ctxt->indent_s
ize * |
1465 » » » » » (ctxt->level + 1 > ctxt->indent_nr ? | 1638 » » » » » (ctxt->level + 1 > ctxt->indent_nr ? |
1466 ctxt->indent_nr : ctxt->level + 1), ctxt
->indent); | 1639 ctxt->indent_nr : ctxt->level + 1), ctxt
->indent); |
1467 } | 1640 } |
1468 xmlOutputBufferWriteString(buf, | 1641 xmlOutputBufferWriteString(buf, |
1469 "<meta http-equiv=\"Content-Type\" content=\"tex
t/html; charset="); | 1642 "<meta http-equiv=\"Content-Type\" content=\"tex
t/html; charset="); |
1470 if (ctxt->encoding) { | 1643 if (ctxt->encoding) { |
1471 xmlOutputBufferWriteString(buf, (const char *)ct
xt->encoding); | 1644 xmlOutputBufferWriteString(buf, (const char *)ct
xt->encoding); |
1472 } else { | 1645 } else { |
1473 xmlOutputBufferWrite(buf, 5, "UTF-8"); | 1646 xmlOutputBufferWrite(buf, 5, "UTF-8"); |
1474 } | 1647 } |
1475 xmlOutputBufferWrite(buf, 4, "\" />"); | 1648 xmlOutputBufferWrite(buf, 4, "\" />"); |
1476 » » » if (ctxt->format) | 1649 » » » if (ctxt->format == 1) |
1477 xmlOutputBufferWrite(buf, 1, "\n"); | 1650 xmlOutputBufferWrite(buf, 1, "\n"); |
1478 } else { | 1651 } else { |
1479 xmlOutputBufferWrite(buf, 1, ">"); | 1652 xmlOutputBufferWrite(buf, 1, ">"); |
1480 } | 1653 } |
1481 /* | 1654 /* |
1482 * C.3. Element Minimization and Empty Element Content | 1655 * C.3. Element Minimization and Empty Element Content |
1483 */ | 1656 */ |
1484 xmlOutputBufferWrite(buf, 2, "</"); | 1657 xmlOutputBufferWrite(buf, 2, "</"); |
1485 if ((cur->ns != NULL) && (cur->ns->prefix != NULL)) { | 1658 if ((cur->ns != NULL) && (cur->ns->prefix != NULL)) { |
1486 xmlOutputBufferWriteString(buf, (const char *)cur->ns->prefix); | 1659 xmlOutputBufferWriteString(buf, (const char *)cur->ns->prefix); |
1487 xmlOutputBufferWrite(buf, 1, ":"); | 1660 xmlOutputBufferWrite(buf, 1, ":"); |
1488 } | 1661 } |
1489 xmlOutputBufferWriteString(buf, (const char *)cur->name); | 1662 xmlOutputBufferWriteString(buf, (const char *)cur->name); |
1490 xmlOutputBufferWrite(buf, 1, ">"); | 1663 xmlOutputBufferWrite(buf, 1, ">"); |
1491 } | 1664 } |
1492 return; | 1665 return; |
1493 } | 1666 } |
1494 xmlOutputBufferWrite(buf, 1, ">"); | 1667 xmlOutputBufferWrite(buf, 1, ">"); |
1495 if (addmeta == 1) { | 1668 if (addmeta == 1) { |
1496 » » if (ctxt->format) { | 1669 » » if (ctxt->format == 1) { |
1497 xmlOutputBufferWrite(buf, 1, "\n"); | 1670 xmlOutputBufferWrite(buf, 1, "\n"); |
1498 if (xmlIndentTreeOutput) | 1671 if (xmlIndentTreeOutput) |
1499 xmlOutputBufferWrite(buf, ctxt->indent_size * | 1672 xmlOutputBufferWrite(buf, ctxt->indent_size * |
1500 » » » » (ctxt->level + 1 > ctxt->indent_nr ? | 1673 » » » » (ctxt->level + 1 > ctxt->indent_nr ? |
1501 ctxt->indent_nr : ctxt->level + 1), ctxt->indent
); | 1674 ctxt->indent_nr : ctxt->level + 1), ctxt->indent
); |
1502 } | 1675 } |
1503 xmlOutputBufferWriteString(buf, | 1676 xmlOutputBufferWriteString(buf, |
1504 "<meta http-equiv=\"Content-Type\" content=\"text/html;
charset="); | 1677 "<meta http-equiv=\"Content-Type\" content=\"text/html;
charset="); |
1505 if (ctxt->encoding) { | 1678 if (ctxt->encoding) { |
1506 xmlOutputBufferWriteString(buf, (const char *)ctxt->enco
ding); | 1679 xmlOutputBufferWriteString(buf, (const char *)ctxt->enco
ding); |
1507 } else { | 1680 } else { |
1508 xmlOutputBufferWrite(buf, 5, "UTF-8"); | 1681 xmlOutputBufferWrite(buf, 5, "UTF-8"); |
1509 } | 1682 } |
1510 xmlOutputBufferWrite(buf, 4, "\" />"); | 1683 xmlOutputBufferWrite(buf, 4, "\" />"); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1580 ctxt->level = level; | 1753 ctxt->level = level; |
1581 ctxt->format = indent; | 1754 ctxt->format = indent; |
1582 } | 1755 } |
1583 child = child->next; | 1756 child = child->next; |
1584 } | 1757 } |
1585 } | 1758 } |
1586 #endif | 1759 #endif |
1587 | 1760 |
1588 if (cur->children != NULL) { | 1761 if (cur->children != NULL) { |
1589 int indent = ctxt->format; | 1762 int indent = ctxt->format; |
1590 » | 1763 |
1591 » if (format) xmlOutputBufferWrite(buf, 1, "\n"); | 1764 » if (format == 1) xmlOutputBufferWrite(buf, 1, "\n"); |
1592 if (ctxt->level >= 0) ctxt->level++; | 1765 if (ctxt->level >= 0) ctxt->level++; |
1593 ctxt->format = format; | 1766 ctxt->format = format; |
1594 xhtmlNodeListDumpOutput(ctxt, cur->children); | 1767 xhtmlNodeListDumpOutput(ctxt, cur->children); |
1595 if (ctxt->level > 0) ctxt->level--; | 1768 if (ctxt->level > 0) ctxt->level--; |
1596 ctxt->format = indent; | 1769 ctxt->format = indent; |
1597 » if ((xmlIndentTreeOutput) && (format)) | 1770 » if ((xmlIndentTreeOutput) && (format == 1)) |
1598 xmlOutputBufferWrite(buf, ctxt->indent_size * | 1771 xmlOutputBufferWrite(buf, ctxt->indent_size * |
1599 » (ctxt->level > ctxt->indent_nr ? | 1772 » (ctxt->level > ctxt->indent_nr ? |
1600 ctxt->indent_nr : ctxt->level), | 1773 ctxt->indent_nr : ctxt->level), |
1601 ctxt->indent); | 1774 ctxt->indent); |
1602 } | 1775 } |
1603 xmlOutputBufferWrite(buf, 2, "</"); | 1776 xmlOutputBufferWrite(buf, 2, "</"); |
1604 if ((cur->ns != NULL) && (cur->ns->prefix != NULL)) { | 1777 if ((cur->ns != NULL) && (cur->ns->prefix != NULL)) { |
1605 xmlOutputBufferWriteString(buf, (const char *)cur->ns->prefix); | 1778 xmlOutputBufferWriteString(buf, (const char *)cur->ns->prefix); |
1606 xmlOutputBufferWrite(buf, 1, ":"); | 1779 xmlOutputBufferWrite(buf, 1, ":"); |
1607 } | 1780 } |
1608 | 1781 |
1609 xmlOutputBufferWriteString(buf, (const char *)cur->name); | 1782 xmlOutputBufferWriteString(buf, (const char *)cur->name); |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1855 if (ctxt == NULL) return(-1); | 2028 if (ctxt == NULL) return(-1); |
1856 ctxt->escapeAttr = escape; | 2029 ctxt->escapeAttr = escape; |
1857 return(0); | 2030 return(0); |
1858 } | 2031 } |
1859 | 2032 |
1860 /************************************************************************ | 2033 /************************************************************************ |
1861 * * | 2034 * * |
1862 * Public entry points based on buffers * | 2035 * Public entry points based on buffers * |
1863 * * | 2036 * * |
1864 ************************************************************************/ | 2037 ************************************************************************/ |
| 2038 |
1865 /** | 2039 /** |
1866 * xmlAttrSerializeTxtContent: | 2040 * xmlBufAttrSerializeTxtContent: |
1867 * @buf: the XML buffer output | 2041 * @buf: and xmlBufPtr output |
1868 * @doc: the document | 2042 * @doc: the document |
1869 * @attr: the attribute node | 2043 * @attr: the attribute node |
1870 * @string: the text content | 2044 * @string: the text content |
1871 * | 2045 * |
1872 * Serialize text attribute values to an xml simple buffer | 2046 * Serialize text attribute values to an xmlBufPtr |
1873 */ | 2047 */ |
1874 void | 2048 void |
1875 xmlAttrSerializeTxtContent(xmlBufferPtr buf, xmlDocPtr doc, | 2049 xmlBufAttrSerializeTxtContent(xmlBufPtr buf, xmlDocPtr doc, |
1876 xmlAttrPtr attr, const xmlChar * string) | 2050 xmlAttrPtr attr, const xmlChar * string) |
1877 { | 2051 { |
1878 xmlChar *base, *cur; | 2052 xmlChar *base, *cur; |
1879 | 2053 |
1880 if (string == NULL) | 2054 if (string == NULL) |
1881 return; | 2055 return; |
1882 base = cur = (xmlChar *) string; | 2056 base = cur = (xmlChar *) string; |
1883 while (*cur != 0) { | 2057 while (*cur != 0) { |
1884 if (*cur == '\n') { | 2058 if (*cur == '\n') { |
1885 if (base != cur) | 2059 if (base != cur) |
1886 xmlBufferAdd(buf, base, cur - base); | 2060 xmlBufAdd(buf, base, cur - base); |
1887 xmlBufferAdd(buf, BAD_CAST " ", 5); | 2061 xmlBufAdd(buf, BAD_CAST " ", 5); |
1888 cur++; | 2062 cur++; |
1889 base = cur; | 2063 base = cur; |
1890 } else if (*cur == '\r') { | 2064 } else if (*cur == '\r') { |
1891 if (base != cur) | 2065 if (base != cur) |
1892 xmlBufferAdd(buf, base, cur - base); | 2066 xmlBufAdd(buf, base, cur - base); |
1893 xmlBufferAdd(buf, BAD_CAST " ", 5); | 2067 xmlBufAdd(buf, BAD_CAST " ", 5); |
1894 cur++; | 2068 cur++; |
1895 base = cur; | 2069 base = cur; |
1896 } else if (*cur == '\t') { | 2070 } else if (*cur == '\t') { |
1897 if (base != cur) | 2071 if (base != cur) |
1898 xmlBufferAdd(buf, base, cur - base); | 2072 xmlBufAdd(buf, base, cur - base); |
1899 xmlBufferAdd(buf, BAD_CAST "	", 4); | 2073 xmlBufAdd(buf, BAD_CAST "	", 4); |
1900 cur++; | 2074 cur++; |
1901 base = cur; | 2075 base = cur; |
1902 } else if (*cur == '"') { | 2076 } else if (*cur == '"') { |
1903 if (base != cur) | 2077 if (base != cur) |
1904 xmlBufferAdd(buf, base, cur - base); | 2078 xmlBufAdd(buf, base, cur - base); |
1905 xmlBufferAdd(buf, BAD_CAST """, 6); | 2079 xmlBufAdd(buf, BAD_CAST """, 6); |
1906 cur++; | 2080 cur++; |
1907 base = cur; | 2081 base = cur; |
1908 } else if (*cur == '<') { | 2082 } else if (*cur == '<') { |
1909 if (base != cur) | 2083 if (base != cur) |
1910 xmlBufferAdd(buf, base, cur - base); | 2084 xmlBufAdd(buf, base, cur - base); |
1911 xmlBufferAdd(buf, BAD_CAST "<", 4); | 2085 xmlBufAdd(buf, BAD_CAST "<", 4); |
1912 cur++; | 2086 cur++; |
1913 base = cur; | 2087 base = cur; |
1914 } else if (*cur == '>') { | 2088 } else if (*cur == '>') { |
1915 if (base != cur) | 2089 if (base != cur) |
1916 xmlBufferAdd(buf, base, cur - base); | 2090 xmlBufAdd(buf, base, cur - base); |
1917 xmlBufferAdd(buf, BAD_CAST ">", 4); | 2091 xmlBufAdd(buf, BAD_CAST ">", 4); |
1918 cur++; | 2092 cur++; |
1919 base = cur; | 2093 base = cur; |
1920 } else if (*cur == '&') { | 2094 } else if (*cur == '&') { |
1921 if (base != cur) | 2095 if (base != cur) |
1922 xmlBufferAdd(buf, base, cur - base); | 2096 xmlBufAdd(buf, base, cur - base); |
1923 xmlBufferAdd(buf, BAD_CAST "&", 5); | 2097 xmlBufAdd(buf, BAD_CAST "&", 5); |
1924 cur++; | 2098 cur++; |
1925 base = cur; | 2099 base = cur; |
1926 } else if ((*cur >= 0x80) && ((doc == NULL) || | 2100 } else if ((*cur >= 0x80) && ((doc == NULL) || |
1927 (doc->encoding == NULL))) { | 2101 (doc->encoding == NULL))) { |
1928 /* | 2102 /* |
1929 * We assume we have UTF-8 content. | 2103 * We assume we have UTF-8 content. |
1930 */ | 2104 */ |
1931 unsigned char tmp[12]; | 2105 unsigned char tmp[12]; |
1932 int val = 0, l = 1; | 2106 int val = 0, l = 1; |
1933 | 2107 |
1934 if (base != cur) | 2108 if (base != cur) |
1935 xmlBufferAdd(buf, base, cur - base); | 2109 xmlBufAdd(buf, base, cur - base); |
1936 if (*cur < 0xC0) { | 2110 if (*cur < 0xC0) { |
1937 xmlSaveErr(XML_SAVE_NOT_UTF8, (xmlNodePtr) attr, NULL); | 2111 xmlSaveErr(XML_SAVE_NOT_UTF8, (xmlNodePtr) attr, NULL); |
1938 if (doc != NULL) | 2112 if (doc != NULL) |
1939 doc->encoding = xmlStrdup(BAD_CAST "ISO-8859-1"); | 2113 doc->encoding = xmlStrdup(BAD_CAST "ISO-8859-1"); |
1940 xmlSerializeHexCharRef(tmp, *cur); | 2114 xmlSerializeHexCharRef(tmp, *cur); |
1941 xmlBufferAdd(buf, (xmlChar *) tmp, -1); | 2115 xmlBufAdd(buf, (xmlChar *) tmp, -1); |
1942 cur++; | 2116 cur++; |
1943 base = cur; | 2117 base = cur; |
1944 continue; | 2118 continue; |
1945 } else if (*cur < 0xE0) { | 2119 } else if (*cur < 0xE0) { |
1946 val = (cur[0]) & 0x1F; | 2120 val = (cur[0]) & 0x1F; |
1947 val <<= 6; | 2121 val <<= 6; |
1948 val |= (cur[1]) & 0x3F; | 2122 val |= (cur[1]) & 0x3F; |
1949 l = 2; | 2123 l = 2; |
1950 } else if (*cur < 0xF0) { | 2124 } else if (*cur < 0xF0) { |
1951 val = (cur[0]) & 0x0F; | 2125 val = (cur[0]) & 0x0F; |
1952 val <<= 6; | 2126 val <<= 6; |
1953 val |= (cur[1]) & 0x3F; | 2127 val |= (cur[1]) & 0x3F; |
1954 val <<= 6; | 2128 val <<= 6; |
1955 val |= (cur[2]) & 0x3F; | 2129 val |= (cur[2]) & 0x3F; |
1956 l = 3; | 2130 l = 3; |
1957 } else if (*cur < 0xF8) { | 2131 } else if (*cur < 0xF8) { |
1958 val = (cur[0]) & 0x07; | 2132 val = (cur[0]) & 0x07; |
1959 val <<= 6; | 2133 val <<= 6; |
1960 val |= (cur[1]) & 0x3F; | 2134 val |= (cur[1]) & 0x3F; |
1961 val <<= 6; | 2135 val <<= 6; |
1962 val |= (cur[2]) & 0x3F; | 2136 val |= (cur[2]) & 0x3F; |
1963 val <<= 6; | 2137 val <<= 6; |
1964 val |= (cur[3]) & 0x3F; | 2138 val |= (cur[3]) & 0x3F; |
1965 l = 4; | 2139 l = 4; |
1966 } | 2140 } |
1967 if ((l == 1) || (!IS_CHAR(val))) { | 2141 if ((l == 1) || (!IS_CHAR(val))) { |
1968 xmlSaveErr(XML_SAVE_CHAR_INVALID, (xmlNodePtr) attr, NULL); | 2142 xmlSaveErr(XML_SAVE_CHAR_INVALID, (xmlNodePtr) attr, NULL); |
1969 if (doc != NULL) | 2143 if (doc != NULL) |
1970 doc->encoding = xmlStrdup(BAD_CAST "ISO-8859-1"); | 2144 doc->encoding = xmlStrdup(BAD_CAST "ISO-8859-1"); |
1971 » » | 2145 |
1972 xmlSerializeHexCharRef(tmp, *cur); | 2146 xmlSerializeHexCharRef(tmp, *cur); |
1973 xmlBufferAdd(buf, (xmlChar *) tmp, -1); | 2147 xmlBufAdd(buf, (xmlChar *) tmp, -1); |
1974 cur++; | 2148 cur++; |
1975 base = cur; | 2149 base = cur; |
1976 continue; | 2150 continue; |
1977 } | 2151 } |
1978 /* | 2152 /* |
1979 * We could do multiple things here. Just save | 2153 * We could do multiple things here. Just save |
1980 * as a char ref | 2154 * as a char ref |
1981 */ | 2155 */ |
1982 xmlSerializeHexCharRef(tmp, val); | 2156 xmlSerializeHexCharRef(tmp, val); |
1983 xmlBufferAdd(buf, (xmlChar *) tmp, -1); | 2157 xmlBufAdd(buf, (xmlChar *) tmp, -1); |
1984 cur += l; | 2158 cur += l; |
1985 base = cur; | 2159 base = cur; |
1986 } else { | 2160 } else { |
1987 cur++; | 2161 cur++; |
1988 } | 2162 } |
1989 } | 2163 } |
1990 if (base != cur) | 2164 if (base != cur) |
1991 xmlBufferAdd(buf, base, cur - base); | 2165 xmlBufAdd(buf, base, cur - base); |
1992 } | 2166 } |
1993 | 2167 |
1994 /** | 2168 /** |
| 2169 * xmlAttrSerializeTxtContent: |
| 2170 * @buf: the XML buffer output |
| 2171 * @doc: the document |
| 2172 * @attr: the attribute node |
| 2173 * @string: the text content |
| 2174 * |
| 2175 * Serialize text attribute values to an xml simple buffer |
| 2176 */ |
| 2177 void |
| 2178 xmlAttrSerializeTxtContent(xmlBufferPtr buf, xmlDocPtr doc, |
| 2179 xmlAttrPtr attr, const xmlChar * string) |
| 2180 { |
| 2181 xmlBufPtr buffer; |
| 2182 |
| 2183 if ((buf == NULL) || (string == NULL)) |
| 2184 return; |
| 2185 buffer = xmlBufFromBuffer(buf); |
| 2186 if (buffer == NULL) |
| 2187 return; |
| 2188 xmlBufAttrSerializeTxtContent(buffer, doc, attr, string); |
| 2189 xmlBufBackToBuffer(buffer); |
| 2190 } |
| 2191 |
| 2192 /** |
1995 * xmlNodeDump: | 2193 * xmlNodeDump: |
1996 * @buf: the XML buffer output | 2194 * @buf: the XML buffer output |
1997 * @doc: the document | 2195 * @doc: the document |
1998 * @cur: the current node | 2196 * @cur: the current node |
1999 * @level: the imbrication level for indenting | 2197 * @level: the imbrication level for indenting |
2000 * @format: is formatting allowed | 2198 * @format: is formatting allowed |
2001 * | 2199 * |
2002 * Dump an XML node, recursive behaviour,children are printed too. | 2200 * Dump an XML node, recursive behaviour,children are printed too. |
2003 * Note that @format = 1 provide node indenting only if xmlIndentTreeOutput = 1 | 2201 * Note that @format = 1 provide node indenting only if xmlIndentTreeOutput = 1 |
2004 * or xmlKeepBlanksDefault(0) was called | 2202 * or xmlKeepBlanksDefault(0) was called |
| 2203 * Since this is using xmlBuffer structures it is limited to 2GB and somehow |
| 2204 * deprecated, use xmlBufNodeDump() instead. |
2005 * | 2205 * |
2006 * Returns the number of bytes written to the buffer or -1 in case of error | 2206 * Returns the number of bytes written to the buffer or -1 in case of error |
2007 */ | 2207 */ |
2008 int | 2208 int |
2009 xmlNodeDump(xmlBufferPtr buf, xmlDocPtr doc, xmlNodePtr cur, int level, | 2209 xmlNodeDump(xmlBufferPtr buf, xmlDocPtr doc, xmlNodePtr cur, int level, |
2010 int format) | 2210 int format) |
2011 { | 2211 { |
2012 unsigned int use; | 2212 xmlBufPtr buffer; |
| 2213 int ret; |
| 2214 |
| 2215 if ((buf == NULL) || (cur == NULL)) |
| 2216 return(-1); |
| 2217 buffer = xmlBufFromBuffer(buf); |
| 2218 if (buffer == NULL) |
| 2219 return(-1); |
| 2220 ret = xmlBufNodeDump(buffer, doc, cur, level, format); |
| 2221 xmlBufBackToBuffer(buffer); |
| 2222 if (ret > INT_MAX) |
| 2223 return(-1); |
| 2224 return((int) ret); |
| 2225 } |
| 2226 |
| 2227 /** |
| 2228 * xmlBufNodeDump: |
| 2229 * @buf: the XML buffer output |
| 2230 * @doc: the document |
| 2231 * @cur: the current node |
| 2232 * @level: the imbrication level for indenting |
| 2233 * @format: is formatting allowed |
| 2234 * |
| 2235 * Dump an XML node, recursive behaviour,children are printed too. |
| 2236 * Note that @format = 1 provide node indenting only if xmlIndentTreeOutput = 1 |
| 2237 * or xmlKeepBlanksDefault(0) was called |
| 2238 * |
| 2239 * Returns the number of bytes written to the buffer, in case of error 0 |
| 2240 * is returned or @buf stores the error |
| 2241 */ |
| 2242 |
| 2243 size_t |
| 2244 xmlBufNodeDump(xmlBufPtr buf, xmlDocPtr doc, xmlNodePtr cur, int level, |
| 2245 int format) |
| 2246 { |
| 2247 size_t use; |
2013 int ret; | 2248 int ret; |
2014 xmlOutputBufferPtr outbuf; | 2249 xmlOutputBufferPtr outbuf; |
| 2250 int oldalloc; |
2015 | 2251 |
2016 xmlInitParser(); | 2252 xmlInitParser(); |
2017 | 2253 |
2018 if (cur == NULL) { | 2254 if (cur == NULL) { |
2019 #ifdef DEBUG_TREE | 2255 #ifdef DEBUG_TREE |
2020 xmlGenericError(xmlGenericErrorContext, | 2256 xmlGenericError(xmlGenericErrorContext, |
2021 "xmlNodeDump : node == NULL\n"); | 2257 "xmlNodeDump : node == NULL\n"); |
2022 #endif | 2258 #endif |
2023 return (-1); | 2259 return (-1); |
2024 } | 2260 } |
(...skipping 10 matching lines...) Expand all Loading... |
2035 return (-1); | 2271 return (-1); |
2036 } | 2272 } |
2037 memset(outbuf, 0, (size_t) sizeof(xmlOutputBuffer)); | 2273 memset(outbuf, 0, (size_t) sizeof(xmlOutputBuffer)); |
2038 outbuf->buffer = buf; | 2274 outbuf->buffer = buf; |
2039 outbuf->encoder = NULL; | 2275 outbuf->encoder = NULL; |
2040 outbuf->writecallback = NULL; | 2276 outbuf->writecallback = NULL; |
2041 outbuf->closecallback = NULL; | 2277 outbuf->closecallback = NULL; |
2042 outbuf->context = NULL; | 2278 outbuf->context = NULL; |
2043 outbuf->written = 0; | 2279 outbuf->written = 0; |
2044 | 2280 |
2045 use = buf->use; | 2281 use = xmlBufUse(buf); |
| 2282 oldalloc = xmlBufGetAllocationScheme(buf); |
| 2283 xmlBufSetAllocationScheme(buf, XML_BUFFER_ALLOC_DOUBLEIT); |
2046 xmlNodeDumpOutput(outbuf, doc, cur, level, format, NULL); | 2284 xmlNodeDumpOutput(outbuf, doc, cur, level, format, NULL); |
| 2285 xmlBufSetAllocationScheme(buf, oldalloc); |
2047 xmlFree(outbuf); | 2286 xmlFree(outbuf); |
2048 ret = buf->use - use; | 2287 ret = xmlBufUse(buf) - use; |
2049 return (ret); | 2288 return (ret); |
2050 } | 2289 } |
2051 | 2290 |
2052 /** | 2291 /** |
2053 * xmlElemDump: | 2292 * xmlElemDump: |
2054 * @f: the FILE * for the output | 2293 * @f: the FILE * for the output |
2055 * @doc: the document | 2294 * @doc: the document |
2056 * @cur: the current node | 2295 * @cur: the current node |
2057 * | 2296 * |
2058 * Dump an XML/HTML node, recursive behaviour, children are printed too. | 2297 * Dump an XML/HTML node, recursive behaviour, children are printed too. |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2125 | 2364 |
2126 if ((buf == NULL) || (cur == NULL)) return; | 2365 if ((buf == NULL) || (cur == NULL)) return; |
2127 | 2366 |
2128 if (encoding == NULL) | 2367 if (encoding == NULL) |
2129 encoding = "UTF-8"; | 2368 encoding = "UTF-8"; |
2130 | 2369 |
2131 memset(&ctxt, 0, sizeof(ctxt)); | 2370 memset(&ctxt, 0, sizeof(ctxt)); |
2132 ctxt.doc = doc; | 2371 ctxt.doc = doc; |
2133 ctxt.buf = buf; | 2372 ctxt.buf = buf; |
2134 ctxt.level = level; | 2373 ctxt.level = level; |
2135 ctxt.format = format; | 2374 ctxt.format = format ? 1 : 0; |
2136 ctxt.encoding = (const xmlChar *) encoding; | 2375 ctxt.encoding = (const xmlChar *) encoding; |
2137 xmlSaveCtxtInit(&ctxt); | 2376 xmlSaveCtxtInit(&ctxt); |
2138 ctxt.options |= XML_SAVE_AS_XML; | 2377 ctxt.options |= XML_SAVE_AS_XML; |
2139 | 2378 |
2140 #ifdef LIBXML_HTML_ENABLED | 2379 #ifdef LIBXML_HTML_ENABLED |
2141 dtd = xmlGetIntSubset(doc); | 2380 dtd = xmlGetIntSubset(doc); |
2142 if (dtd != NULL) { | 2381 if (dtd != NULL) { |
2143 is_xhtml = xmlIsXHTML(dtd->SystemID, dtd->ExternalID); | 2382 is_xhtml = xmlIsXHTML(dtd->SystemID, dtd->ExternalID); |
2144 if (is_xhtml < 0) | 2383 if (is_xhtml < 0) |
2145 is_xhtml = 0; | 2384 is_xhtml = 0; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2211 | 2450 |
2212 if ((out_buff = xmlAllocOutputBuffer(conv_hdlr)) == NULL ) { | 2451 if ((out_buff = xmlAllocOutputBuffer(conv_hdlr)) == NULL ) { |
2213 xmlSaveErrMemory("creating buffer"); | 2452 xmlSaveErrMemory("creating buffer"); |
2214 return; | 2453 return; |
2215 } | 2454 } |
2216 | 2455 |
2217 memset(&ctxt, 0, sizeof(ctxt)); | 2456 memset(&ctxt, 0, sizeof(ctxt)); |
2218 ctxt.doc = out_doc; | 2457 ctxt.doc = out_doc; |
2219 ctxt.buf = out_buff; | 2458 ctxt.buf = out_buff; |
2220 ctxt.level = 0; | 2459 ctxt.level = 0; |
2221 ctxt.format = format; | 2460 ctxt.format = format ? 1 : 0; |
2222 ctxt.encoding = (const xmlChar *) txt_encoding; | 2461 ctxt.encoding = (const xmlChar *) txt_encoding; |
2223 xmlSaveCtxtInit(&ctxt); | 2462 xmlSaveCtxtInit(&ctxt); |
2224 ctxt.options |= XML_SAVE_AS_XML; | 2463 ctxt.options |= XML_SAVE_AS_XML; |
2225 xmlDocContentDumpOutput(&ctxt, out_doc); | 2464 xmlDocContentDumpOutput(&ctxt, out_doc); |
2226 xmlOutputBufferFlush(out_buff); | 2465 xmlOutputBufferFlush(out_buff); |
2227 if (out_buff->conv != NULL) { | 2466 if (out_buff->conv != NULL) { |
2228 » *doc_txt_len = out_buff->conv->use; | 2467 » *doc_txt_len = xmlBufUse(out_buff->conv); |
2229 » *doc_txt_ptr = xmlStrndup(out_buff->conv->content, *doc_txt_len); | 2468 » *doc_txt_ptr = xmlStrndup(xmlBufContent(out_buff->conv), *doc_txt_len); |
2230 } else { | 2469 } else { |
2231 » *doc_txt_len = out_buff->buffer->use; | 2470 » *doc_txt_len = xmlBufUse(out_buff->buffer); |
2232 » *doc_txt_ptr = xmlStrndup(out_buff->buffer->content, *doc_txt_len); | 2471 » *doc_txt_ptr = xmlStrndup(xmlBufContent(out_buff->buffer),*doc_txt_len); |
2233 } | 2472 } |
2234 (void)xmlOutputBufferClose(out_buff); | 2473 (void)xmlOutputBufferClose(out_buff); |
2235 | 2474 |
2236 if ((*doc_txt_ptr == NULL) && (*doc_txt_len > 0)) { | 2475 if ((*doc_txt_ptr == NULL) && (*doc_txt_len > 0)) { |
2237 *doc_txt_len = 0; | 2476 *doc_txt_len = 0; |
2238 xmlSaveErrMemory("creating output"); | 2477 xmlSaveErrMemory("creating output"); |
2239 } | 2478 } |
2240 | 2479 |
2241 return; | 2480 return; |
2242 } | 2481 } |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2330 cur->encoding = NULL; | 2569 cur->encoding = NULL; |
2331 encoding = NULL; | 2570 encoding = NULL; |
2332 } | 2571 } |
2333 } | 2572 } |
2334 buf = xmlOutputBufferCreateFile(f, handler); | 2573 buf = xmlOutputBufferCreateFile(f, handler); |
2335 if (buf == NULL) return(-1); | 2574 if (buf == NULL) return(-1); |
2336 memset(&ctxt, 0, sizeof(ctxt)); | 2575 memset(&ctxt, 0, sizeof(ctxt)); |
2337 ctxt.doc = cur; | 2576 ctxt.doc = cur; |
2338 ctxt.buf = buf; | 2577 ctxt.buf = buf; |
2339 ctxt.level = 0; | 2578 ctxt.level = 0; |
2340 ctxt.format = format; | 2579 ctxt.format = format ? 1 : 0; |
2341 ctxt.encoding = (const xmlChar *) encoding; | 2580 ctxt.encoding = (const xmlChar *) encoding; |
2342 xmlSaveCtxtInit(&ctxt); | 2581 xmlSaveCtxtInit(&ctxt); |
2343 ctxt.options |= XML_SAVE_AS_XML; | 2582 ctxt.options |= XML_SAVE_AS_XML; |
2344 xmlDocContentDumpOutput(&ctxt, cur); | 2583 xmlDocContentDumpOutput(&ctxt, cur); |
2345 | 2584 |
2346 ret = xmlOutputBufferClose(buf); | 2585 ret = xmlOutputBufferClose(buf); |
2347 return(ret); | 2586 return(ret); |
2348 } | 2587 } |
2349 | 2588 |
2350 /** | 2589 /** |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2420 if ((cur == NULL) || | 2659 if ((cur == NULL) || |
2421 ((cur->type != XML_DOCUMENT_NODE) && | 2660 ((cur->type != XML_DOCUMENT_NODE) && |
2422 (cur->type != XML_HTML_DOCUMENT_NODE))) { | 2661 (cur->type != XML_HTML_DOCUMENT_NODE))) { |
2423 xmlOutputBufferClose(buf); | 2662 xmlOutputBufferClose(buf); |
2424 return(-1); | 2663 return(-1); |
2425 } | 2664 } |
2426 memset(&ctxt, 0, sizeof(ctxt)); | 2665 memset(&ctxt, 0, sizeof(ctxt)); |
2427 ctxt.doc = cur; | 2666 ctxt.doc = cur; |
2428 ctxt.buf = buf; | 2667 ctxt.buf = buf; |
2429 ctxt.level = 0; | 2668 ctxt.level = 0; |
2430 ctxt.format = format; | 2669 ctxt.format = format ? 1 : 0; |
2431 ctxt.encoding = (const xmlChar *) encoding; | 2670 ctxt.encoding = (const xmlChar *) encoding; |
2432 xmlSaveCtxtInit(&ctxt); | 2671 xmlSaveCtxtInit(&ctxt); |
2433 ctxt.options |= XML_SAVE_AS_XML; | 2672 ctxt.options |= XML_SAVE_AS_XML; |
2434 xmlDocContentDumpOutput(&ctxt, cur); | 2673 xmlDocContentDumpOutput(&ctxt, cur); |
2435 ret = xmlOutputBufferClose(buf); | 2674 ret = xmlOutputBufferClose(buf); |
2436 return (ret); | 2675 return (ret); |
2437 } | 2676 } |
2438 | 2677 |
2439 /** | 2678 /** |
2440 * xmlSaveFormatFileEnc: | 2679 * xmlSaveFormatFileEnc: |
(...skipping 25 matching lines...) Expand all Loading... |
2466 if (encoding != NULL) { | 2705 if (encoding != NULL) { |
2467 | 2706 |
2468 handler = xmlFindCharEncodingHandler(encoding); | 2707 handler = xmlFindCharEncodingHandler(encoding); |
2469 if (handler == NULL) | 2708 if (handler == NULL) |
2470 return(-1); | 2709 return(-1); |
2471 } | 2710 } |
2472 | 2711 |
2473 #ifdef HAVE_ZLIB_H | 2712 #ifdef HAVE_ZLIB_H |
2474 if (cur->compression < 0) cur->compression = xmlGetCompressMode(); | 2713 if (cur->compression < 0) cur->compression = xmlGetCompressMode(); |
2475 #endif | 2714 #endif |
2476 /* | 2715 /* |
2477 * save the content to a temp buffer. | 2716 * save the content to a temp buffer. |
2478 */ | 2717 */ |
2479 buf = xmlOutputBufferCreateFilename(filename, handler, cur->compression); | 2718 buf = xmlOutputBufferCreateFilename(filename, handler, cur->compression); |
2480 if (buf == NULL) return(-1); | 2719 if (buf == NULL) return(-1); |
2481 memset(&ctxt, 0, sizeof(ctxt)); | 2720 memset(&ctxt, 0, sizeof(ctxt)); |
2482 ctxt.doc = cur; | 2721 ctxt.doc = cur; |
2483 ctxt.buf = buf; | 2722 ctxt.buf = buf; |
2484 ctxt.level = 0; | 2723 ctxt.level = 0; |
2485 ctxt.format = format; | 2724 ctxt.format = format ? 1 : 0; |
2486 ctxt.encoding = (const xmlChar *) encoding; | 2725 ctxt.encoding = (const xmlChar *) encoding; |
2487 xmlSaveCtxtInit(&ctxt); | 2726 xmlSaveCtxtInit(&ctxt); |
2488 ctxt.options |= XML_SAVE_AS_XML; | 2727 ctxt.options |= XML_SAVE_AS_XML; |
2489 | 2728 |
2490 xmlDocContentDumpOutput(&ctxt, cur); | 2729 xmlDocContentDumpOutput(&ctxt, cur); |
2491 | 2730 |
2492 ret = xmlOutputBufferClose(buf); | 2731 ret = xmlOutputBufferClose(buf); |
2493 return(ret); | 2732 return(ret); |
2494 } | 2733 } |
2495 | 2734 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2540 */ | 2779 */ |
2541 int | 2780 int |
2542 xmlSaveFile(const char *filename, xmlDocPtr cur) { | 2781 xmlSaveFile(const char *filename, xmlDocPtr cur) { |
2543 return(xmlSaveFormatFileEnc(filename, cur, NULL, 0)); | 2782 return(xmlSaveFormatFileEnc(filename, cur, NULL, 0)); |
2544 } | 2783 } |
2545 | 2784 |
2546 #endif /* LIBXML_OUTPUT_ENABLED */ | 2785 #endif /* LIBXML_OUTPUT_ENABLED */ |
2547 | 2786 |
2548 #define bottom_xmlsave | 2787 #define bottom_xmlsave |
2549 #include "elfgcchack.h" | 2788 #include "elfgcchack.h" |
OLD | NEW |