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" |
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 children = children->next; | 450 children = children->next; |
451 } | 451 } |
452 } | 452 } |
453 | 453 |
454 /************************************************************************ | 454 /************************************************************************ |
455 * * | 455 * * |
456 * Dumping XML tree content to an I/O output buffer * | 456 * Dumping XML tree content to an I/O output buffer * |
457 * * | 457 * * |
458 ************************************************************************/ | 458 ************************************************************************/ |
459 | 459 |
| 460 static int xmlSaveSwitchEncoding(xmlSaveCtxtPtr ctxt, const char *encoding) { |
| 461 xmlOutputBufferPtr buf = ctxt->buf; |
| 462 |
| 463 if ((encoding != NULL) && (buf->encoder == NULL) && (buf->conv == NULL)) { |
| 464 buf->encoder = xmlFindCharEncodingHandler((const char *)encoding); |
| 465 if (buf->encoder == NULL) { |
| 466 xmlSaveErr(XML_SAVE_UNKNOWN_ENCODING, NULL, |
| 467 (const char *)encoding); |
| 468 return(-1); |
| 469 } |
| 470 buf->conv = xmlBufferCreate(); |
| 471 if (buf->conv == NULL) { |
| 472 xmlCharEncCloseFunc(buf->encoder); |
| 473 xmlSaveErrMemory("creating encoding buffer"); |
| 474 return(-1); |
| 475 } |
| 476 /* |
| 477 * initialize the state, e.g. if outputting a BOM |
| 478 */ |
| 479 xmlCharEncOutFunc(buf->encoder, buf->conv, NULL); |
| 480 } |
| 481 return(0); |
| 482 } |
| 483 |
| 484 static int xmlSaveClearEncoding(xmlSaveCtxtPtr ctxt) { |
| 485 xmlOutputBufferPtr buf = ctxt->buf; |
| 486 xmlOutputBufferFlush(buf); |
| 487 xmlCharEncCloseFunc(buf->encoder); |
| 488 xmlBufferFree(buf->conv); |
| 489 buf->encoder = NULL; |
| 490 buf->conv = NULL; |
| 491 return(0); |
| 492 } |
| 493 |
460 #ifdef LIBXML_HTML_ENABLED | 494 #ifdef LIBXML_HTML_ENABLED |
461 static void | 495 static void |
462 xhtmlNodeDumpOutput(xmlSaveCtxtPtr ctxt, xmlNodePtr cur); | 496 xhtmlNodeDumpOutput(xmlSaveCtxtPtr ctxt, xmlNodePtr cur); |
463 #endif | 497 #endif |
464 static void xmlNodeListDumpOutput(xmlSaveCtxtPtr ctxt, xmlNodePtr cur); | 498 static void xmlNodeListDumpOutput(xmlSaveCtxtPtr ctxt, xmlNodePtr cur); |
465 static void xmlNodeDumpOutputInternal(xmlSaveCtxtPtr ctxt, xmlNodePtr cur); | 499 static void xmlNodeDumpOutputInternal(xmlSaveCtxtPtr ctxt, xmlNodePtr cur); |
466 void xmlNsListDumpOutput(xmlOutputBufferPtr buf, xmlNsPtr cur); | 500 void xmlNsListDumpOutput(xmlOutputBufferPtr buf, xmlNsPtr cur); |
467 static int xmlDocContentDumpOutput(xmlSaveCtxtPtr ctxt, xmlDocPtr cur); | 501 static int xmlDocContentDumpOutput(xmlSaveCtxtPtr ctxt, xmlDocPtr cur); |
468 | 502 |
469 /** | 503 /** |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
631 ctxt->indent_nr : ctxt->level), | 665 ctxt->indent_nr : ctxt->level), |
632 ctxt->indent); | 666 ctxt->indent); |
633 xmlNodeDumpOutputInternal(ctxt, cur); | 667 xmlNodeDumpOutputInternal(ctxt, cur); |
634 if (ctxt->format) { | 668 if (ctxt->format) { |
635 xmlOutputBufferWrite(buf, 1, "\n"); | 669 xmlOutputBufferWrite(buf, 1, "\n"); |
636 } | 670 } |
637 cur = cur->next; | 671 cur = cur->next; |
638 } | 672 } |
639 } | 673 } |
640 | 674 |
| 675 #ifdef LIBXML_HTML_ENABLED |
| 676 /** |
| 677 * xmlNodeDumpOutputInternal: |
| 678 * @cur: the current node |
| 679 * |
| 680 * Dump an HTML node, recursive behaviour, children are printed too. |
| 681 */ |
| 682 static int |
| 683 htmlNodeDumpOutputInternal(xmlSaveCtxtPtr ctxt, xmlNodePtr cur) { |
| 684 const xmlChar *oldenc = NULL; |
| 685 const xmlChar *oldctxtenc = ctxt->encoding; |
| 686 const xmlChar *encoding = ctxt->encoding; |
| 687 xmlOutputBufferPtr buf = ctxt->buf; |
| 688 int switched_encoding = 0; |
| 689 xmlDocPtr doc; |
| 690 |
| 691 xmlInitParser(); |
| 692 |
| 693 doc = cur->doc; |
| 694 if (doc != NULL) { |
| 695 oldenc = doc->encoding; |
| 696 if (ctxt->encoding != NULL) { |
| 697 doc->encoding = BAD_CAST ctxt->encoding; |
| 698 } else if (doc->encoding != NULL) { |
| 699 encoding = doc->encoding; |
| 700 } |
| 701 } |
| 702 |
| 703 if ((encoding != NULL) && (doc != NULL)) |
| 704 htmlSetMetaEncoding(doc, (const xmlChar *) encoding); |
| 705 if ((encoding == NULL) && (doc != NULL)) |
| 706 encoding = htmlGetMetaEncoding(doc); |
| 707 if (encoding == NULL) |
| 708 encoding = BAD_CAST "HTML"; |
| 709 if ((encoding != NULL) && (oldctxtenc == NULL) && |
| 710 (buf->encoder == NULL) && (buf->conv == NULL)) { |
| 711 if (xmlSaveSwitchEncoding(ctxt, (const char*) encoding) < 0) { |
| 712 doc->encoding = oldenc; |
| 713 return(-1); |
| 714 } |
| 715 switched_encoding = 1; |
| 716 } |
| 717 if (ctxt->options & XML_SAVE_FORMAT) |
| 718 htmlNodeDumpFormatOutput(buf, doc, cur, |
| 719 (const char *)encoding, 1); |
| 720 else |
| 721 htmlNodeDumpFormatOutput(buf, doc, cur, |
| 722 (const char *)encoding, 0); |
| 723 /* |
| 724 * Restore the state of the saving context at the end of the document |
| 725 */ |
| 726 if ((switched_encoding) && (oldctxtenc == NULL)) { |
| 727 xmlSaveClearEncoding(ctxt); |
| 728 } |
| 729 if (doc != NULL) |
| 730 doc->encoding = oldenc; |
| 731 return(0); |
| 732 } |
| 733 #endif |
| 734 |
641 /** | 735 /** |
642 * xmlNodeDumpOutputInternal: | 736 * xmlNodeDumpOutputInternal: |
643 * @cur: the current node | 737 * @cur: the current node |
644 * | 738 * |
645 * Dump an XML node, recursive behaviour, children are printed too. | 739 * Dump an XML node, recursive behaviour, children are printed too. |
646 */ | 740 */ |
647 static void | 741 static void |
648 xmlNodeDumpOutputInternal(xmlSaveCtxtPtr ctxt, xmlNodePtr cur) { | 742 xmlNodeDumpOutputInternal(xmlSaveCtxtPtr ctxt, xmlNodePtr cur) { |
649 int format; | 743 int format; |
650 xmlNodePtr tmp; | 744 xmlNodePtr tmp; |
651 xmlChar *start, *end; | 745 xmlChar *start, *end; |
652 xmlOutputBufferPtr buf; | 746 xmlOutputBufferPtr buf; |
653 | 747 |
654 if (cur == NULL) return; | 748 if (cur == NULL) return; |
655 buf = ctxt->buf; | 749 buf = ctxt->buf; |
656 if (cur->type == XML_XINCLUDE_START) | 750 if (cur->type == XML_XINCLUDE_START) |
657 return; | 751 return; |
658 if (cur->type == XML_XINCLUDE_END) | 752 if (cur->type == XML_XINCLUDE_END) |
659 return; | 753 return; |
660 if ((cur->type == XML_DOCUMENT_NODE) || | 754 if ((cur->type == XML_DOCUMENT_NODE) || |
661 (cur->type == XML_HTML_DOCUMENT_NODE)) { | 755 (cur->type == XML_HTML_DOCUMENT_NODE)) { |
662 xmlDocContentDumpOutput(ctxt, (xmlDocPtr) cur); | 756 xmlDocContentDumpOutput(ctxt, (xmlDocPtr) cur); |
663 return; | 757 return; |
664 } | 758 } |
| 759 #ifdef LIBXML_HTML_ENABLED |
| 760 if (ctxt->options & XML_SAVE_XHTML) { |
| 761 xhtmlNodeDumpOutput(ctxt, cur); |
| 762 return; |
| 763 } |
| 764 if (((cur->type != XML_NAMESPACE_DECL) && (cur->doc != NULL) && |
| 765 (cur->doc->type == XML_HTML_DOCUMENT_NODE) && |
| 766 ((ctxt->options & XML_SAVE_AS_XML) == 0)) || |
| 767 (ctxt->options & XML_SAVE_AS_HTML)) { |
| 768 htmlNodeDumpOutputInternal(ctxt, cur); |
| 769 return; |
| 770 } |
| 771 #endif |
665 if (cur->type == XML_DTD_NODE) { | 772 if (cur->type == XML_DTD_NODE) { |
666 xmlDtdDumpOutput(ctxt, (xmlDtdPtr) cur); | 773 xmlDtdDumpOutput(ctxt, (xmlDtdPtr) cur); |
667 return; | 774 return; |
668 } | 775 } |
669 if (cur->type == XML_DOCUMENT_FRAG_NODE) { | 776 if (cur->type == XML_DOCUMENT_FRAG_NODE) { |
670 xmlNodeListDumpOutput(ctxt, cur->children); | 777 xmlNodeListDumpOutput(ctxt, cur->children); |
671 return; | 778 return; |
672 } | 779 } |
673 if (cur->type == XML_ELEMENT_DECL) { | 780 if (cur->type == XML_ELEMENT_DECL) { |
674 xmlDumpElementDecl(buf->buffer, (xmlElementPtr) cur); | 781 xmlDumpElementDecl(buf->buffer, (xmlElementPtr) cur); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
828 xmlDtdPtr dtd; | 935 xmlDtdPtr dtd; |
829 int is_xhtml = 0; | 936 int is_xhtml = 0; |
830 #endif | 937 #endif |
831 const xmlChar *oldenc = cur->encoding; | 938 const xmlChar *oldenc = cur->encoding; |
832 const xmlChar *oldctxtenc = ctxt->encoding; | 939 const xmlChar *oldctxtenc = ctxt->encoding; |
833 const xmlChar *encoding = ctxt->encoding; | 940 const xmlChar *encoding = ctxt->encoding; |
834 xmlCharEncodingOutputFunc oldescape = ctxt->escape; | 941 xmlCharEncodingOutputFunc oldescape = ctxt->escape; |
835 xmlCharEncodingOutputFunc oldescapeAttr = ctxt->escapeAttr; | 942 xmlCharEncodingOutputFunc oldescapeAttr = ctxt->escapeAttr; |
836 xmlOutputBufferPtr buf = ctxt->buf; | 943 xmlOutputBufferPtr buf = ctxt->buf; |
837 xmlCharEncoding enc; | 944 xmlCharEncoding enc; |
| 945 int switched_encoding = 0; |
838 | 946 |
839 xmlInitParser(); | 947 xmlInitParser(); |
840 | 948 |
| 949 if ((cur->type != XML_HTML_DOCUMENT_NODE) && |
| 950 (cur->type != XML_DOCUMENT_NODE)) |
| 951 return(-1); |
| 952 |
841 if (ctxt->encoding != NULL) { | 953 if (ctxt->encoding != NULL) { |
842 cur->encoding = BAD_CAST ctxt->encoding; | 954 cur->encoding = BAD_CAST ctxt->encoding; |
843 } else if (cur->encoding != NULL) { | 955 } else if (cur->encoding != NULL) { |
844 encoding = cur->encoding; | 956 encoding = cur->encoding; |
845 } else if (cur->charset != XML_CHAR_ENCODING_UTF8) { | 957 } else if (cur->charset != XML_CHAR_ENCODING_UTF8) { |
846 encoding = (const xmlChar *) | 958 encoding = (const xmlChar *) |
847 xmlGetCharEncodingName((xmlCharEncoding) cur->charset); | 959 xmlGetCharEncodingName((xmlCharEncoding) cur->charset); |
848 } | 960 } |
849 | 961 |
850 enc = xmlParseCharEncoding((const char*) encoding); | 962 if (((cur->type == XML_HTML_DOCUMENT_NODE) && |
851 if ((encoding != NULL) && (oldctxtenc == NULL) && | 963 ((ctxt->options & XML_SAVE_AS_XML) == 0) && |
852 (buf->encoder == NULL) && (buf->conv == NULL) && | 964 ((ctxt->options & XML_SAVE_XHTML) == 0)) || |
853 » ((ctxt->options & XML_SAVE_NO_DECL) == 0)) { | 965 (ctxt->options & XML_SAVE_AS_HTML)) { |
854 » if ((enc != XML_CHAR_ENCODING_UTF8) && | 966 #ifdef LIBXML_HTML_ENABLED |
855 » (enc != XML_CHAR_ENCODING_NONE) && | 967 if (encoding != NULL) |
856 » (enc != XML_CHAR_ENCODING_ASCII)) { | 968 » htmlSetMetaEncoding(cur, (const xmlChar *) encoding); |
857 » /* | 969 if (encoding == NULL) |
858 » * we need to switch to this encoding but just for this document | 970 » encoding = htmlGetMetaEncoding(cur); |
859 » * since we output the XMLDecl the conversion must be done to not | 971 if (encoding == NULL) |
860 » * generate not well formed documents. | 972 » encoding = BAD_CAST "HTML"; |
861 » */ | 973 » if ((encoding != NULL) && (oldctxtenc == NULL) && |
862 » buf->encoder = xmlFindCharEncodingHandler((const char *)encoding); | 974 » (buf->encoder == NULL) && (buf->conv == NULL)) { |
863 » if (buf->encoder == NULL) { | 975 » if (xmlSaveSwitchEncoding(ctxt, (const char*) encoding) < 0) { |
864 » » xmlSaveErr(XML_SAVE_UNKNOWN_ENCODING, NULL, | 976 » » cur->encoding = oldenc; |
865 » » (const char *)encoding); | |
866 return(-1); | 977 return(-1); |
867 } | 978 } |
868 » buf->conv = xmlBufferCreate(); | 979 » } |
869 » if (buf->conv == NULL) { | 980 if (ctxt->options & XML_SAVE_FORMAT) |
870 » » xmlCharEncCloseFunc(buf->encoder); | 981 » htmlDocContentDumpFormatOutput(buf, cur, |
871 » » xmlSaveErrMemory("creating encoding buffer"); | 982 » (const char *)encoding, 1); |
872 » » return(-1); | 983 » else |
| 984 » htmlDocContentDumpFormatOutput(buf, cur, |
| 985 » (const char *)encoding, 0); |
| 986 » if (ctxt->encoding != NULL) |
| 987 » cur->encoding = oldenc; |
| 988 » return(0); |
| 989 #else |
| 990 return(-1); |
| 991 #endif |
| 992 } else if ((cur->type == XML_DOCUMENT_NODE) || |
| 993 (ctxt->options & XML_SAVE_AS_XML) || |
| 994 (ctxt->options & XML_SAVE_XHTML)) { |
| 995 » enc = xmlParseCharEncoding((const char*) encoding); |
| 996 » if ((encoding != NULL) && (oldctxtenc == NULL) && |
| 997 » (buf->encoder == NULL) && (buf->conv == NULL) && |
| 998 » ((ctxt->options & XML_SAVE_NO_DECL) == 0)) { |
| 999 » if ((enc != XML_CHAR_ENCODING_UTF8) && |
| 1000 » » (enc != XML_CHAR_ENCODING_NONE) && |
| 1001 » » (enc != XML_CHAR_ENCODING_ASCII)) { |
| 1002 » » /* |
| 1003 » » * we need to switch to this encoding but just for this |
| 1004 » » * document since we output the XMLDecl the conversion |
| 1005 » » * must be done to not generate not well formed documents. |
| 1006 » » */ |
| 1007 » » if (xmlSaveSwitchEncoding(ctxt, (const char*) encoding) < 0) { |
| 1008 » » cur->encoding = oldenc; |
| 1009 » » return(-1); |
| 1010 » » } |
| 1011 » » switched_encoding = 1; |
873 } | 1012 } |
874 » /* | 1013 » if (ctxt->escape == xmlEscapeEntities) |
875 » * initialize the state, e.g. if outputting a BOM | 1014 » » ctxt->escape = NULL; |
876 » */ | 1015 » if (ctxt->escapeAttr == xmlEscapeEntities) |
877 » xmlCharEncOutFunc(buf->encoder, buf->conv, NULL); | 1016 » » ctxt->escapeAttr = NULL; |
878 } | 1017 } |
879 » if (ctxt->escape == xmlEscapeEntities) | 1018 |
880 » ctxt->escape = NULL; | 1019 |
881 » if (ctxt->escapeAttr == xmlEscapeEntities) | 1020 » /* |
882 » ctxt->escapeAttr = NULL; | 1021 » * Save the XML declaration |
| 1022 » */ |
| 1023 » if ((ctxt->options & XML_SAVE_NO_DECL) == 0) { |
| 1024 » xmlOutputBufferWrite(buf, 14, "<?xml version="); |
| 1025 » if (cur->version != NULL) |
| 1026 » » xmlBufferWriteQuotedString(buf->buffer, cur->version); |
| 1027 » else |
| 1028 » » xmlOutputBufferWrite(buf, 5, "\"1.0\""); |
| 1029 » if (encoding != NULL) { |
| 1030 » » xmlOutputBufferWrite(buf, 10, " encoding="); |
| 1031 » » xmlBufferWriteQuotedString(buf->buffer, (xmlChar *) encoding); |
| 1032 » } |
| 1033 » switch (cur->standalone) { |
| 1034 » » case 0: |
| 1035 » » xmlOutputBufferWrite(buf, 16, " standalone=\"no\""); |
| 1036 » » break; |
| 1037 » » case 1: |
| 1038 » » xmlOutputBufferWrite(buf, 17, " standalone=\"yes\""); |
| 1039 » » break; |
| 1040 » } |
| 1041 » xmlOutputBufferWrite(buf, 3, "?>\n"); |
| 1042 » } |
| 1043 |
| 1044 #ifdef LIBXML_HTML_ENABLED |
| 1045 if (ctxt->options & XML_SAVE_XHTML) |
| 1046 is_xhtml = 1; |
| 1047 » if ((ctxt->options & XML_SAVE_NO_XHTML) == 0) { |
| 1048 » dtd = xmlGetIntSubset(cur); |
| 1049 » if (dtd != NULL) { |
| 1050 » » is_xhtml = xmlIsXHTML(dtd->SystemID, dtd->ExternalID); |
| 1051 » » if (is_xhtml < 0) is_xhtml = 0; |
| 1052 » } |
| 1053 » } |
| 1054 #endif |
| 1055 » if (cur->children != NULL) { |
| 1056 » xmlNodePtr child = cur->children; |
| 1057 |
| 1058 » while (child != NULL) { |
| 1059 » » ctxt->level = 0; |
| 1060 #ifdef LIBXML_HTML_ENABLED |
| 1061 » » if (is_xhtml) |
| 1062 » » xhtmlNodeDumpOutput(ctxt, child); |
| 1063 » » else |
| 1064 #endif |
| 1065 » » xmlNodeDumpOutputInternal(ctxt, child); |
| 1066 » » xmlOutputBufferWrite(buf, 1, "\n"); |
| 1067 » » child = child->next; |
| 1068 » } |
| 1069 » } |
883 } | 1070 } |
884 | 1071 |
885 | |
886 /* | |
887 * Save the XML declaration | |
888 */ | |
889 if ((ctxt->options & XML_SAVE_NO_DECL) == 0) { | |
890 xmlOutputBufferWrite(buf, 14, "<?xml version="); | |
891 if (cur->version != NULL) | |
892 xmlBufferWriteQuotedString(buf->buffer, cur->version); | |
893 else | |
894 xmlOutputBufferWrite(buf, 5, "\"1.0\""); | |
895 if (encoding != NULL) { | |
896 xmlOutputBufferWrite(buf, 10, " encoding="); | |
897 xmlBufferWriteQuotedString(buf->buffer, (xmlChar *) encoding); | |
898 } | |
899 switch (cur->standalone) { | |
900 case 0: | |
901 xmlOutputBufferWrite(buf, 16, " standalone=\"no\""); | |
902 break; | |
903 case 1: | |
904 xmlOutputBufferWrite(buf, 17, " standalone=\"yes\""); | |
905 break; | |
906 } | |
907 xmlOutputBufferWrite(buf, 3, "?>\n"); | |
908 } | |
909 | |
910 #ifdef LIBXML_HTML_ENABLED | |
911 if ((ctxt->options & XML_SAVE_NO_XHTML) == 0) { | |
912 dtd = xmlGetIntSubset(cur); | |
913 if (dtd != NULL) { | |
914 is_xhtml = xmlIsXHTML(dtd->SystemID, dtd->ExternalID); | |
915 if (is_xhtml < 0) is_xhtml = 0; | |
916 } | |
917 } | |
918 #endif | |
919 if (cur->children != NULL) { | |
920 xmlNodePtr child = cur->children; | |
921 | |
922 while (child != NULL) { | |
923 ctxt->level = 0; | |
924 #ifdef LIBXML_HTML_ENABLED | |
925 if (is_xhtml) | |
926 xhtmlNodeDumpOutput(ctxt, child); | |
927 else | |
928 #endif | |
929 xmlNodeDumpOutputInternal(ctxt, child); | |
930 xmlOutputBufferWrite(buf, 1, "\n"); | |
931 child = child->next; | |
932 } | |
933 } | |
934 if (ctxt->encoding != NULL) | |
935 cur->encoding = oldenc; | |
936 | |
937 /* | 1072 /* |
938 * Restore the state of the saving context at the end of the document | 1073 * Restore the state of the saving context at the end of the document |
939 */ | 1074 */ |
940 if ((encoding != NULL) && (oldctxtenc == NULL) && | 1075 if ((switched_encoding) && (oldctxtenc == NULL)) { |
941 » ((ctxt->options & XML_SAVE_NO_DECL) == 0)) { | 1076 » xmlSaveClearEncoding(ctxt); |
942 » if ((enc != XML_CHAR_ENCODING_UTF8) && | |
943 » (enc != XML_CHAR_ENCODING_NONE) && | |
944 » (enc != XML_CHAR_ENCODING_ASCII)) { | |
945 » xmlOutputBufferFlush(buf); | |
946 » xmlCharEncCloseFunc(buf->encoder); | |
947 » xmlBufferFree(buf->conv); | |
948 » buf->encoder = NULL; | |
949 » buf->conv = NULL; | |
950 » } | |
951 ctxt->escape = oldescape; | 1077 ctxt->escape = oldescape; |
952 ctxt->escapeAttr = oldescapeAttr; | 1078 ctxt->escapeAttr = oldescapeAttr; |
953 } | 1079 } |
| 1080 cur->encoding = oldenc; |
954 return(0); | 1081 return(0); |
955 } | 1082 } |
956 | 1083 |
957 #ifdef LIBXML_HTML_ENABLED | 1084 #ifdef LIBXML_HTML_ENABLED |
958 /************************************************************************ | 1085 /************************************************************************ |
959 * * | 1086 * * |
960 * Functions specific to XHTML serialization * | 1087 * Functions specific to XHTML serialization * |
961 * * | 1088 * * |
962 ************************************************************************/ | 1089 ************************************************************************/ |
963 | 1090 |
(...skipping 1037 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2001 if (encoding == NULL) | 2128 if (encoding == NULL) |
2002 encoding = "UTF-8"; | 2129 encoding = "UTF-8"; |
2003 | 2130 |
2004 memset(&ctxt, 0, sizeof(ctxt)); | 2131 memset(&ctxt, 0, sizeof(ctxt)); |
2005 ctxt.doc = doc; | 2132 ctxt.doc = doc; |
2006 ctxt.buf = buf; | 2133 ctxt.buf = buf; |
2007 ctxt.level = level; | 2134 ctxt.level = level; |
2008 ctxt.format = format; | 2135 ctxt.format = format; |
2009 ctxt.encoding = (const xmlChar *) encoding; | 2136 ctxt.encoding = (const xmlChar *) encoding; |
2010 xmlSaveCtxtInit(&ctxt); | 2137 xmlSaveCtxtInit(&ctxt); |
| 2138 ctxt.options |= XML_SAVE_AS_XML; |
2011 | 2139 |
2012 #ifdef LIBXML_HTML_ENABLED | 2140 #ifdef LIBXML_HTML_ENABLED |
2013 dtd = xmlGetIntSubset(doc); | 2141 dtd = xmlGetIntSubset(doc); |
2014 if (dtd != NULL) { | 2142 if (dtd != NULL) { |
2015 is_xhtml = xmlIsXHTML(dtd->SystemID, dtd->ExternalID); | 2143 is_xhtml = xmlIsXHTML(dtd->SystemID, dtd->ExternalID); |
2016 if (is_xhtml < 0) | 2144 if (is_xhtml < 0) |
2017 is_xhtml = 0; | 2145 is_xhtml = 0; |
2018 } | 2146 } |
2019 | 2147 |
2020 if (is_xhtml) | 2148 if (is_xhtml) |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2086 return; | 2214 return; |
2087 } | 2215 } |
2088 | 2216 |
2089 memset(&ctxt, 0, sizeof(ctxt)); | 2217 memset(&ctxt, 0, sizeof(ctxt)); |
2090 ctxt.doc = out_doc; | 2218 ctxt.doc = out_doc; |
2091 ctxt.buf = out_buff; | 2219 ctxt.buf = out_buff; |
2092 ctxt.level = 0; | 2220 ctxt.level = 0; |
2093 ctxt.format = format; | 2221 ctxt.format = format; |
2094 ctxt.encoding = (const xmlChar *) txt_encoding; | 2222 ctxt.encoding = (const xmlChar *) txt_encoding; |
2095 xmlSaveCtxtInit(&ctxt); | 2223 xmlSaveCtxtInit(&ctxt); |
| 2224 ctxt.options |= XML_SAVE_AS_XML; |
2096 xmlDocContentDumpOutput(&ctxt, out_doc); | 2225 xmlDocContentDumpOutput(&ctxt, out_doc); |
2097 xmlOutputBufferFlush(out_buff); | 2226 xmlOutputBufferFlush(out_buff); |
2098 if (out_buff->conv != NULL) { | 2227 if (out_buff->conv != NULL) { |
2099 *doc_txt_len = out_buff->conv->use; | 2228 *doc_txt_len = out_buff->conv->use; |
2100 *doc_txt_ptr = xmlStrndup(out_buff->conv->content, *doc_txt_len); | 2229 *doc_txt_ptr = xmlStrndup(out_buff->conv->content, *doc_txt_len); |
2101 } else { | 2230 } else { |
2102 *doc_txt_len = out_buff->buffer->use; | 2231 *doc_txt_len = out_buff->buffer->use; |
2103 *doc_txt_ptr = xmlStrndup(out_buff->buffer->content, *doc_txt_len); | 2232 *doc_txt_ptr = xmlStrndup(out_buff->buffer->content, *doc_txt_len); |
2104 } | 2233 } |
2105 (void)xmlOutputBufferClose(out_buff); | 2234 (void)xmlOutputBufferClose(out_buff); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2204 } | 2333 } |
2205 buf = xmlOutputBufferCreateFile(f, handler); | 2334 buf = xmlOutputBufferCreateFile(f, handler); |
2206 if (buf == NULL) return(-1); | 2335 if (buf == NULL) return(-1); |
2207 memset(&ctxt, 0, sizeof(ctxt)); | 2336 memset(&ctxt, 0, sizeof(ctxt)); |
2208 ctxt.doc = cur; | 2337 ctxt.doc = cur; |
2209 ctxt.buf = buf; | 2338 ctxt.buf = buf; |
2210 ctxt.level = 0; | 2339 ctxt.level = 0; |
2211 ctxt.format = format; | 2340 ctxt.format = format; |
2212 ctxt.encoding = (const xmlChar *) encoding; | 2341 ctxt.encoding = (const xmlChar *) encoding; |
2213 xmlSaveCtxtInit(&ctxt); | 2342 xmlSaveCtxtInit(&ctxt); |
| 2343 ctxt.options |= XML_SAVE_AS_XML; |
2214 xmlDocContentDumpOutput(&ctxt, cur); | 2344 xmlDocContentDumpOutput(&ctxt, cur); |
2215 | 2345 |
2216 ret = xmlOutputBufferClose(buf); | 2346 ret = xmlOutputBufferClose(buf); |
2217 return(ret); | 2347 return(ret); |
2218 } | 2348 } |
2219 | 2349 |
2220 /** | 2350 /** |
2221 * xmlDocDump: | 2351 * xmlDocDump: |
2222 * @f: the FILE* | 2352 * @f: the FILE* |
2223 * @cur: the document | 2353 * @cur: the document |
(...skipping 29 matching lines...) Expand all Loading... |
2253 xmlOutputBufferClose(buf); | 2383 xmlOutputBufferClose(buf); |
2254 return(-1); | 2384 return(-1); |
2255 } | 2385 } |
2256 memset(&ctxt, 0, sizeof(ctxt)); | 2386 memset(&ctxt, 0, sizeof(ctxt)); |
2257 ctxt.doc = cur; | 2387 ctxt.doc = cur; |
2258 ctxt.buf = buf; | 2388 ctxt.buf = buf; |
2259 ctxt.level = 0; | 2389 ctxt.level = 0; |
2260 ctxt.format = 0; | 2390 ctxt.format = 0; |
2261 ctxt.encoding = (const xmlChar *) encoding; | 2391 ctxt.encoding = (const xmlChar *) encoding; |
2262 xmlSaveCtxtInit(&ctxt); | 2392 xmlSaveCtxtInit(&ctxt); |
| 2393 ctxt.options |= XML_SAVE_AS_XML; |
2263 xmlDocContentDumpOutput(&ctxt, cur); | 2394 xmlDocContentDumpOutput(&ctxt, cur); |
2264 ret = xmlOutputBufferClose(buf); | 2395 ret = xmlOutputBufferClose(buf); |
2265 return(ret); | 2396 return(ret); |
2266 } | 2397 } |
2267 | 2398 |
2268 /** | 2399 /** |
2269 * xmlSaveFormatFileTo: | 2400 * xmlSaveFormatFileTo: |
2270 * @buf: an output I/O buffer | 2401 * @buf: an output I/O buffer |
2271 * @cur: the document | 2402 * @cur: the document |
2272 * @encoding: the encoding if any assuming the I/O layer handles the trancoding | 2403 * @encoding: the encoding if any assuming the I/O layer handles the trancoding |
(...skipping 19 matching lines...) Expand all Loading... |
2292 xmlOutputBufferClose(buf); | 2423 xmlOutputBufferClose(buf); |
2293 return(-1); | 2424 return(-1); |
2294 } | 2425 } |
2295 memset(&ctxt, 0, sizeof(ctxt)); | 2426 memset(&ctxt, 0, sizeof(ctxt)); |
2296 ctxt.doc = cur; | 2427 ctxt.doc = cur; |
2297 ctxt.buf = buf; | 2428 ctxt.buf = buf; |
2298 ctxt.level = 0; | 2429 ctxt.level = 0; |
2299 ctxt.format = format; | 2430 ctxt.format = format; |
2300 ctxt.encoding = (const xmlChar *) encoding; | 2431 ctxt.encoding = (const xmlChar *) encoding; |
2301 xmlSaveCtxtInit(&ctxt); | 2432 xmlSaveCtxtInit(&ctxt); |
| 2433 ctxt.options |= XML_SAVE_AS_XML; |
2302 xmlDocContentDumpOutput(&ctxt, cur); | 2434 xmlDocContentDumpOutput(&ctxt, cur); |
2303 ret = xmlOutputBufferClose(buf); | 2435 ret = xmlOutputBufferClose(buf); |
2304 return (ret); | 2436 return (ret); |
2305 } | 2437 } |
2306 | 2438 |
2307 /** | 2439 /** |
2308 * xmlSaveFormatFileEnc: | 2440 * xmlSaveFormatFileEnc: |
2309 * @filename: the filename or URL to output | 2441 * @filename: the filename or URL to output |
2310 * @cur: the document being saved | 2442 * @cur: the document being saved |
2311 * @encoding: the name of the encoding to use or NULL. | 2443 * @encoding: the name of the encoding to use or NULL. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2346 */ | 2478 */ |
2347 buf = xmlOutputBufferCreateFilename(filename, handler, cur->compression); | 2479 buf = xmlOutputBufferCreateFilename(filename, handler, cur->compression); |
2348 if (buf == NULL) return(-1); | 2480 if (buf == NULL) return(-1); |
2349 memset(&ctxt, 0, sizeof(ctxt)); | 2481 memset(&ctxt, 0, sizeof(ctxt)); |
2350 ctxt.doc = cur; | 2482 ctxt.doc = cur; |
2351 ctxt.buf = buf; | 2483 ctxt.buf = buf; |
2352 ctxt.level = 0; | 2484 ctxt.level = 0; |
2353 ctxt.format = format; | 2485 ctxt.format = format; |
2354 ctxt.encoding = (const xmlChar *) encoding; | 2486 ctxt.encoding = (const xmlChar *) encoding; |
2355 xmlSaveCtxtInit(&ctxt); | 2487 xmlSaveCtxtInit(&ctxt); |
| 2488 ctxt.options |= XML_SAVE_AS_XML; |
2356 | 2489 |
2357 xmlDocContentDumpOutput(&ctxt, cur); | 2490 xmlDocContentDumpOutput(&ctxt, cur); |
2358 | 2491 |
2359 ret = xmlOutputBufferClose(buf); | 2492 ret = xmlOutputBufferClose(buf); |
2360 return(ret); | 2493 return(ret); |
2361 } | 2494 } |
2362 | 2495 |
2363 | 2496 |
2364 /** | 2497 /** |
2365 * xmlSaveFileEnc: | 2498 * xmlSaveFileEnc: |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2407 */ | 2540 */ |
2408 int | 2541 int |
2409 xmlSaveFile(const char *filename, xmlDocPtr cur) { | 2542 xmlSaveFile(const char *filename, xmlDocPtr cur) { |
2410 return(xmlSaveFormatFileEnc(filename, cur, NULL, 0)); | 2543 return(xmlSaveFormatFileEnc(filename, cur, NULL, 0)); |
2411 } | 2544 } |
2412 | 2545 |
2413 #endif /* LIBXML_OUTPUT_ENABLED */ | 2546 #endif /* LIBXML_OUTPUT_ENABLED */ |
2414 | 2547 |
2415 #define bottom_xmlsave | 2548 #define bottom_xmlsave |
2416 #include "elfgcchack.h" | 2549 #include "elfgcchack.h" |
OLD | NEW |