2 * entities.c : implementation for the XML entities handling
4 * See Copyright for the status of this software.
16 #include <libxml/xmlmemory.h>
17 #include <libxml/hash.h>
18 #include <libxml/entities.h>
19 #include <libxml/parser.h>
20 #include <libxml/parserInternals.h>
21 #include <libxml/xmlerror.h>
22 #include <libxml/globals.h>
23 #include <libxml/dict.h>
26 * The XML predefined entities.
29 static xmlEntity xmlEntityLt = {
30 NULL, XML_ENTITY_DECL, BAD_CAST "lt",
31 NULL, NULL, NULL, NULL, NULL, NULL,
32 BAD_CAST "<", BAD_CAST "<", 1,
33 XML_INTERNAL_PREDEFINED_ENTITY,
34 NULL, NULL, NULL, NULL, 0, 1
36 static xmlEntity xmlEntityGt = {
37 NULL, XML_ENTITY_DECL, BAD_CAST "gt",
38 NULL, NULL, NULL, NULL, NULL, NULL,
39 BAD_CAST ">", BAD_CAST ">", 1,
40 XML_INTERNAL_PREDEFINED_ENTITY,
41 NULL, NULL, NULL, NULL, 0, 1
43 static xmlEntity xmlEntityAmp = {
44 NULL, XML_ENTITY_DECL, BAD_CAST "amp",
45 NULL, NULL, NULL, NULL, NULL, NULL,
46 BAD_CAST "&", BAD_CAST "&", 1,
47 XML_INTERNAL_PREDEFINED_ENTITY,
48 NULL, NULL, NULL, NULL, 0, 1
50 static xmlEntity xmlEntityQuot = {
51 NULL, XML_ENTITY_DECL, BAD_CAST "quot",
52 NULL, NULL, NULL, NULL, NULL, NULL,
53 BAD_CAST "\"", BAD_CAST "\"", 1,
54 XML_INTERNAL_PREDEFINED_ENTITY,
55 NULL, NULL, NULL, NULL, 0, 1
57 static xmlEntity xmlEntityApos = {
58 NULL, XML_ENTITY_DECL, BAD_CAST "apos",
59 NULL, NULL, NULL, NULL, NULL, NULL,
60 BAD_CAST "'", BAD_CAST "'", 1,
61 XML_INTERNAL_PREDEFINED_ENTITY,
62 NULL, NULL, NULL, NULL, 0, 1
66 * xmlEntitiesErrMemory:
67 * @extra: extra informations
69 * Handle an out of memory condition
72 xmlEntitiesErrMemory(const char *extra)
74 __xmlSimpleError(XML_FROM_TREE, XML_ERR_NO_MEMORY, NULL, NULL, extra);
79 * @code: the error code
82 * Handle an out of memory condition
85 xmlEntitiesErr(xmlParserErrors code, const char *msg)
87 __xmlSimpleError(XML_FROM_TREE, code, NULL, msg, NULL);
91 * xmlFreeEntity : clean-up an entity record.
94 xmlFreeEntity(xmlEntityPtr entity)
96 xmlDictPtr dict = NULL;
101 if (entity->doc != NULL)
102 dict = entity->doc->dict;
105 if ((entity->children) && (entity->owner == 1) &&
106 (entity == (xmlEntityPtr) entity->children->parent))
107 xmlFreeNodeList(entity->children);
109 if ((entity->name != NULL) && (!xmlDictOwns(dict, entity->name)))
110 xmlFree((char *) entity->name);
111 if ((entity->ExternalID != NULL) &&
112 (!xmlDictOwns(dict, entity->ExternalID)))
113 xmlFree((char *) entity->ExternalID);
114 if ((entity->SystemID != NULL) &&
115 (!xmlDictOwns(dict, entity->SystemID)))
116 xmlFree((char *) entity->SystemID);
117 if ((entity->URI != NULL) && (!xmlDictOwns(dict, entity->URI)))
118 xmlFree((char *) entity->URI);
119 if ((entity->content != NULL)
120 && (!xmlDictOwns(dict, entity->content)))
121 xmlFree((char *) entity->content);
122 if ((entity->orig != NULL) && (!xmlDictOwns(dict, entity->orig)))
123 xmlFree((char *) entity->orig);
125 if (entity->name != NULL)
126 xmlFree((char *) entity->name);
127 if (entity->ExternalID != NULL)
128 xmlFree((char *) entity->ExternalID);
129 if (entity->SystemID != NULL)
130 xmlFree((char *) entity->SystemID);
131 if (entity->URI != NULL)
132 xmlFree((char *) entity->URI);
133 if (entity->content != NULL)
134 xmlFree((char *) entity->content);
135 if (entity->orig != NULL)
136 xmlFree((char *) entity->orig);
142 * xmlAddEntity : register a new entity for an entities table.
145 xmlAddEntity(xmlDtdPtr dtd, const xmlChar *name, int type,
146 const xmlChar *ExternalID, const xmlChar *SystemID,
147 const xmlChar *content) {
148 xmlDictPtr dict = NULL;
149 xmlEntitiesTablePtr table = NULL;
156 if (dtd->doc != NULL)
157 dict = dtd->doc->dict;
160 case XML_INTERNAL_GENERAL_ENTITY:
161 case XML_EXTERNAL_GENERAL_PARSED_ENTITY:
162 case XML_EXTERNAL_GENERAL_UNPARSED_ENTITY:
163 if (dtd->entities == NULL)
164 dtd->entities = xmlHashCreateDict(0, dict);
165 table = dtd->entities;
167 case XML_INTERNAL_PARAMETER_ENTITY:
168 case XML_EXTERNAL_PARAMETER_ENTITY:
169 if (dtd->pentities == NULL)
170 dtd->pentities = xmlHashCreateDict(0, dict);
171 table = dtd->pentities;
173 case XML_INTERNAL_PREDEFINED_ENTITY:
178 ret = (xmlEntityPtr) xmlMalloc(sizeof(xmlEntity));
180 xmlEntitiesErrMemory("xmlAddEntity:: malloc failed");
183 memset(ret, 0, sizeof(xmlEntity));
184 ret->type = XML_ENTITY_DECL;
188 * fill the structure.
190 ret->etype = (xmlEntityType) type;
192 ret->name = xmlStrdup(name);
193 if (ExternalID != NULL)
194 ret->ExternalID = xmlStrdup(ExternalID);
195 if (SystemID != NULL)
196 ret->SystemID = xmlStrdup(SystemID);
198 ret->name = xmlDictLookup(dict, name, -1);
199 if (ExternalID != NULL)
200 ret->ExternalID = xmlDictLookup(dict, ExternalID, -1);
201 if (SystemID != NULL)
202 ret->SystemID = xmlDictLookup(dict, SystemID, -1);
204 if (content != NULL) {
205 ret->length = xmlStrlen(content);
206 if ((dict != NULL) && (ret->length < 5))
207 ret->content = (xmlChar *)
208 xmlDictLookup(dict, content, ret->length);
210 ret->content = xmlStrndup(content, ret->length);
215 ret->URI = NULL; /* to be computed by the layer knowing
216 the defining entity */
221 if (xmlHashAddEntry(table, name, ret)) {
223 * entity was already defined at another level.
232 * xmlGetPredefinedEntity:
233 * @name: the entity name
235 * Check whether this name is an predefined entity.
237 * Returns NULL if not, otherwise the entity
240 xmlGetPredefinedEntity(const xmlChar *name) {
241 if (name == NULL) return(NULL);
244 if (xmlStrEqual(name, BAD_CAST "lt"))
245 return(&xmlEntityLt);
248 if (xmlStrEqual(name, BAD_CAST "gt"))
249 return(&xmlEntityGt);
252 if (xmlStrEqual(name, BAD_CAST "amp"))
253 return(&xmlEntityAmp);
254 if (xmlStrEqual(name, BAD_CAST "apos"))
255 return(&xmlEntityApos);
258 if (xmlStrEqual(name, BAD_CAST "quot"))
259 return(&xmlEntityQuot);
270 * @name: the entity name
271 * @type: the entity type XML_xxx_yyy_ENTITY
272 * @ExternalID: the entity external ID if available
273 * @SystemID: the entity system ID if available
274 * @content: the entity content
276 * Register a new entity for this document DTD external subset.
278 * Returns a pointer to the entity or NULL in case of error
281 xmlAddDtdEntity(xmlDocPtr doc, const xmlChar *name, int type,
282 const xmlChar *ExternalID, const xmlChar *SystemID,
283 const xmlChar *content) {
288 xmlEntitiesErr(XML_DTD_NO_DOC,
289 "xmlAddDtdEntity: document is NULL");
292 if (doc->extSubset == NULL) {
293 xmlEntitiesErr(XML_DTD_NO_DTD,
294 "xmlAddDtdEntity: document without external subset");
297 dtd = doc->extSubset;
298 ret = xmlAddEntity(dtd, name, type, ExternalID, SystemID, content);
299 if (ret == NULL) return(NULL);
306 if (dtd->last == NULL) {
307 dtd->children = dtd->last = (xmlNodePtr) ret;
309 dtd->last->next = (xmlNodePtr) ret;
310 ret->prev = dtd->last;
311 dtd->last = (xmlNodePtr) ret;
319 * @name: the entity name
320 * @type: the entity type XML_xxx_yyy_ENTITY
321 * @ExternalID: the entity external ID if available
322 * @SystemID: the entity system ID if available
323 * @content: the entity content
325 * Register a new entity for this document.
327 * Returns a pointer to the entity or NULL in case of error
330 xmlAddDocEntity(xmlDocPtr doc, const xmlChar *name, int type,
331 const xmlChar *ExternalID, const xmlChar *SystemID,
332 const xmlChar *content) {
337 xmlEntitiesErr(XML_DTD_NO_DOC,
338 "xmlAddDocEntity: document is NULL");
341 if (doc->intSubset == NULL) {
342 xmlEntitiesErr(XML_DTD_NO_DTD,
343 "xmlAddDocEntity: document without internal subset");
346 dtd = doc->intSubset;
347 ret = xmlAddEntity(dtd, name, type, ExternalID, SystemID, content);
348 if (ret == NULL) return(NULL);
355 if (dtd->last == NULL) {
356 dtd->children = dtd->last = (xmlNodePtr) ret;
358 dtd->last->next = (xmlNodePtr) ret;
359 ret->prev = dtd->last;
360 dtd->last = (xmlNodePtr) ret;
366 * xmlGetEntityFromTable:
367 * @table: an entity table
368 * @name: the entity name
369 * @parameter: look for parameter entities
371 * Do an entity lookup in the table.
372 * returns the corresponding parameter entity, if found.
374 * Returns A pointer to the entity structure or NULL if not found.
377 xmlGetEntityFromTable(xmlEntitiesTablePtr table, const xmlChar *name) {
378 return((xmlEntityPtr) xmlHashLookup(table, name));
382 * xmlGetParameterEntity:
383 * @doc: the document referencing the entity
384 * @name: the entity name
386 * Do an entity lookup in the internal and external subsets and
387 * returns the corresponding parameter entity, if found.
389 * Returns A pointer to the entity structure or NULL if not found.
392 xmlGetParameterEntity(xmlDocPtr doc, const xmlChar *name) {
393 xmlEntitiesTablePtr table;
398 if ((doc->intSubset != NULL) && (doc->intSubset->pentities != NULL)) {
399 table = (xmlEntitiesTablePtr) doc->intSubset->pentities;
400 ret = xmlGetEntityFromTable(table, name);
404 if ((doc->extSubset != NULL) && (doc->extSubset->pentities != NULL)) {
405 table = (xmlEntitiesTablePtr) doc->extSubset->pentities;
406 return(xmlGetEntityFromTable(table, name));
413 * @doc: the document referencing the entity
414 * @name: the entity name
416 * Do an entity lookup in the DTD entity hash table and
417 * returns the corresponding entity, if found.
418 * Note: the first argument is the document node, not the DTD node.
420 * Returns A pointer to the entity structure or NULL if not found.
423 xmlGetDtdEntity(xmlDocPtr doc, const xmlChar *name) {
424 xmlEntitiesTablePtr table;
428 if ((doc->extSubset != NULL) && (doc->extSubset->entities != NULL)) {
429 table = (xmlEntitiesTablePtr) doc->extSubset->entities;
430 return(xmlGetEntityFromTable(table, name));
437 * @doc: the document referencing the entity
438 * @name: the entity name
440 * Do an entity lookup in the document entity hash table and
441 * returns the corresponding entity, otherwise a lookup is done
442 * in the predefined entities too.
444 * Returns A pointer to the entity structure or NULL if not found.
447 xmlGetDocEntity(xmlDocPtr doc, const xmlChar *name) {
449 xmlEntitiesTablePtr table;
452 if ((doc->intSubset != NULL) && (doc->intSubset->entities != NULL)) {
453 table = (xmlEntitiesTablePtr) doc->intSubset->entities;
454 cur = xmlGetEntityFromTable(table, name);
458 if (doc->standalone != 1) {
459 if ((doc->extSubset != NULL) &&
460 (doc->extSubset->entities != NULL)) {
461 table = (xmlEntitiesTablePtr) doc->extSubset->entities;
462 cur = xmlGetEntityFromTable(table, name);
468 return(xmlGetPredefinedEntity(name));
472 * Macro used to grow the current buffer.
474 #define growBufferReentrant() { \
476 buffer = (xmlChar *) \
477 xmlRealloc(buffer, buffer_size * sizeof(xmlChar)); \
478 if (buffer == NULL) { \
479 xmlEntitiesErrMemory("xmlEncodeEntitiesReentrant: realloc failed");\
486 * xmlEncodeEntitiesReentrant:
487 * @doc: the document containing the string
488 * @input: A string to convert to XML.
490 * Do a global encoding of a string, replacing the predefined entities
491 * and non ASCII values with their entities and CharRef counterparts.
492 * Contrary to xmlEncodeEntities, this routine is reentrant, and result
493 * must be deallocated.
495 * Returns A newly allocated string with the substitution done.
498 xmlEncodeEntitiesReentrant(xmlDocPtr doc, const xmlChar *input) {
499 const xmlChar *cur = input;
500 xmlChar *buffer = NULL;
505 if (input == NULL) return(NULL);
507 html = (doc->type == XML_HTML_DOCUMENT_NODE);
510 * allocate an translation buffer.
513 buffer = (xmlChar *) xmlMalloc(buffer_size * sizeof(xmlChar));
514 if (buffer == NULL) {
515 xmlEntitiesErrMemory("xmlEncodeEntitiesReentrant: malloc failed");
520 while (*cur != '\0') {
521 if (out - buffer > buffer_size - 100) {
522 int indx = out - buffer;
524 growBufferReentrant();
529 * By default one have to encode at least '<', '>', '"' and '&' !
536 } else if (*cur == '>') {
541 } else if (*cur == '&') {
547 } else if (((*cur >= 0x20) && (*cur < 0x80)) ||
548 (*cur == '\n') || (*cur == '\t') || ((html) && (*cur == '\r'))) {
550 * default case, just copy !
553 } else if (*cur >= 0x80) {
554 if (((doc != NULL) && (doc->encoding != NULL)) || (html)) {
556 * Bjørn Reese <br@sseusa.com> provided the patch
558 xc = (*cur & 0x3F) << 6;
560 xc += *(++cur) & 0x3F;
567 * We assume we have UTF-8 input.
573 xmlEntitiesErr(XML_CHECK_NOT_UTF8,
574 "xmlEncodeEntitiesReentrant : input not UTF-8");
576 doc->encoding = xmlStrdup(BAD_CAST "ISO-8859-1");
577 snprintf(buf, sizeof(buf), "&#%d;", *cur);
578 buf[sizeof(buf) - 1] = 0;
580 while (*ptr != 0) *out++ = *ptr++;
583 } else if (*cur < 0xE0) {
584 val = (cur[0]) & 0x1F;
586 val |= (cur[1]) & 0x3F;
588 } else if (*cur < 0xF0) {
589 val = (cur[0]) & 0x0F;
591 val |= (cur[1]) & 0x3F;
593 val |= (cur[2]) & 0x3F;
595 } else if (*cur < 0xF8) {
596 val = (cur[0]) & 0x07;
598 val |= (cur[1]) & 0x3F;
600 val |= (cur[2]) & 0x3F;
602 val |= (cur[3]) & 0x3F;
605 if ((l == 1) || (!IS_CHAR(val))) {
606 xmlEntitiesErr(XML_ERR_INVALID_CHAR,
607 "xmlEncodeEntitiesReentrant : char out of range\n");
609 doc->encoding = xmlStrdup(BAD_CAST "ISO-8859-1");
610 snprintf(buf, sizeof(buf), "&#%d;", *cur);
611 buf[sizeof(buf) - 1] = 0;
613 while (*ptr != 0) *out++ = *ptr++;
618 * We could do multiple things here. Just save as a char ref
620 snprintf(buf, sizeof(buf), "&#x%X;", val);
621 buf[sizeof(buf) - 1] = 0;
623 while (*ptr != 0) *out++ = *ptr++;
627 } else if (IS_BYTE_CHAR(*cur)) {
630 snprintf(buf, sizeof(buf), "&#%d;", *cur);
631 buf[sizeof(buf) - 1] = 0;
633 while (*ptr != 0) *out++ = *ptr++;
642 * xmlEncodeSpecialChars:
643 * @doc: the document containing the string
644 * @input: A string to convert to XML.
646 * Do a global encoding of a string, replacing the predefined entities
647 * this routine is reentrant, and result must be deallocated.
649 * Returns A newly allocated string with the substitution done.
652 xmlEncodeSpecialChars(xmlDocPtr doc ATTRIBUTE_UNUSED, const xmlChar *input) {
653 const xmlChar *cur = input;
654 xmlChar *buffer = NULL;
657 if (input == NULL) return(NULL);
660 * allocate an translation buffer.
663 buffer = (xmlChar *) xmlMalloc(buffer_size * sizeof(xmlChar));
664 if (buffer == NULL) {
665 xmlEntitiesErrMemory("xmlEncodeSpecialChars: malloc failed");
670 while (*cur != '\0') {
671 if (out - buffer > buffer_size - 10) {
672 int indx = out - buffer;
674 growBufferReentrant();
679 * By default one have to encode at least '<', '>', '"' and '&' !
686 } else if (*cur == '>') {
691 } else if (*cur == '&') {
697 } else if (*cur == '"') {
704 } else if (*cur == '\r') {
712 * Works because on UTF-8, all extended sequences cannot
713 * result in bytes in the ASCII range.
724 * xmlCreateEntitiesTable:
726 * create and initialize an empty entities hash table.
727 * This really doesn't make sense and should be deprecated
729 * Returns the xmlEntitiesTablePtr just created or NULL in case of error.
732 xmlCreateEntitiesTable(void) {
733 return((xmlEntitiesTablePtr) xmlHashCreate(0));
737 * xmlFreeEntityWrapper:
741 * Deallocate the memory used by an entities in the hash table.
744 xmlFreeEntityWrapper(xmlEntityPtr entity,
745 const xmlChar *name ATTRIBUTE_UNUSED) {
747 xmlFreeEntity(entity);
751 * xmlFreeEntitiesTable:
752 * @table: An entity table
754 * Deallocate the memory used by an entities hash table.
757 xmlFreeEntitiesTable(xmlEntitiesTablePtr table) {
758 xmlHashFree(table, (xmlHashDeallocator) xmlFreeEntityWrapper);
761 #ifdef LIBXML_TREE_ENABLED
766 * Build a copy of an entity
768 * Returns the new xmlEntitiesPtr or NULL in case of error.
771 xmlCopyEntity(xmlEntityPtr ent) {
774 cur = (xmlEntityPtr) xmlMalloc(sizeof(xmlEntity));
776 xmlEntitiesErrMemory("xmlCopyEntity:: malloc failed");
779 memset(cur, 0, sizeof(xmlEntity));
780 cur->type = XML_ENTITY_DECL;
782 cur->etype = ent->etype;
783 if (ent->name != NULL)
784 cur->name = xmlStrdup(ent->name);
785 if (ent->ExternalID != NULL)
786 cur->ExternalID = xmlStrdup(ent->ExternalID);
787 if (ent->SystemID != NULL)
788 cur->SystemID = xmlStrdup(ent->SystemID);
789 if (ent->content != NULL)
790 cur->content = xmlStrdup(ent->content);
791 if (ent->orig != NULL)
792 cur->orig = xmlStrdup(ent->orig);
793 if (ent->URI != NULL)
794 cur->URI = xmlStrdup(ent->URI);
799 * xmlCopyEntitiesTable:
800 * @table: An entity table
802 * Build a copy of an entity table.
804 * Returns the new xmlEntitiesTablePtr or NULL in case of error.
807 xmlCopyEntitiesTable(xmlEntitiesTablePtr table) {
808 return(xmlHashCopy(table, (xmlHashCopier) xmlCopyEntity));
810 #endif /* LIBXML_TREE_ENABLED */
812 #ifdef LIBXML_OUTPUT_ENABLED
815 * xmlDumpEntityContent:
816 * @buf: An XML buffer.
817 * @content: The entity content.
819 * This will dump the quoted string value, taking care of the special
820 * treatment required by %
823 xmlDumpEntityContent(xmlBufferPtr buf, const xmlChar *content) {
824 if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return;
825 if (xmlStrchr(content, '%')) {
826 const xmlChar * base, *cur;
828 xmlBufferCCat(buf, "\"");
829 base = cur = content;
833 xmlBufferAdd(buf, base, cur - base);
834 xmlBufferAdd(buf, BAD_CAST """, 6);
837 } else if (*cur == '%') {
839 xmlBufferAdd(buf, base, cur - base);
840 xmlBufferAdd(buf, BAD_CAST "%", 6);
848 xmlBufferAdd(buf, base, cur - base);
849 xmlBufferCCat(buf, "\"");
851 xmlBufferWriteQuotedString(buf, content);
857 * @buf: An XML buffer.
858 * @ent: An entity table
860 * This will dump the content of the entity table as an XML DTD definition
863 xmlDumpEntityDecl(xmlBufferPtr buf, xmlEntityPtr ent) {
864 if ((buf == NULL) || (ent == NULL)) return;
865 switch (ent->etype) {
866 case XML_INTERNAL_GENERAL_ENTITY:
867 xmlBufferWriteChar(buf, "<!ENTITY ");
868 xmlBufferWriteCHAR(buf, ent->name);
869 xmlBufferWriteChar(buf, " ");
870 if (ent->orig != NULL)
871 xmlBufferWriteQuotedString(buf, ent->orig);
873 xmlDumpEntityContent(buf, ent->content);
874 xmlBufferWriteChar(buf, ">\n");
876 case XML_EXTERNAL_GENERAL_PARSED_ENTITY:
877 xmlBufferWriteChar(buf, "<!ENTITY ");
878 xmlBufferWriteCHAR(buf, ent->name);
879 if (ent->ExternalID != NULL) {
880 xmlBufferWriteChar(buf, " PUBLIC ");
881 xmlBufferWriteQuotedString(buf, ent->ExternalID);
882 xmlBufferWriteChar(buf, " ");
883 xmlBufferWriteQuotedString(buf, ent->SystemID);
885 xmlBufferWriteChar(buf, " SYSTEM ");
886 xmlBufferWriteQuotedString(buf, ent->SystemID);
888 xmlBufferWriteChar(buf, ">\n");
890 case XML_EXTERNAL_GENERAL_UNPARSED_ENTITY:
891 xmlBufferWriteChar(buf, "<!ENTITY ");
892 xmlBufferWriteCHAR(buf, ent->name);
893 if (ent->ExternalID != NULL) {
894 xmlBufferWriteChar(buf, " PUBLIC ");
895 xmlBufferWriteQuotedString(buf, ent->ExternalID);
896 xmlBufferWriteChar(buf, " ");
897 xmlBufferWriteQuotedString(buf, ent->SystemID);
899 xmlBufferWriteChar(buf, " SYSTEM ");
900 xmlBufferWriteQuotedString(buf, ent->SystemID);
902 if (ent->content != NULL) { /* Should be true ! */
903 xmlBufferWriteChar(buf, " NDATA ");
904 if (ent->orig != NULL)
905 xmlBufferWriteCHAR(buf, ent->orig);
907 xmlBufferWriteCHAR(buf, ent->content);
909 xmlBufferWriteChar(buf, ">\n");
911 case XML_INTERNAL_PARAMETER_ENTITY:
912 xmlBufferWriteChar(buf, "<!ENTITY % ");
913 xmlBufferWriteCHAR(buf, ent->name);
914 xmlBufferWriteChar(buf, " ");
915 if (ent->orig == NULL)
916 xmlDumpEntityContent(buf, ent->content);
918 xmlBufferWriteQuotedString(buf, ent->orig);
919 xmlBufferWriteChar(buf, ">\n");
921 case XML_EXTERNAL_PARAMETER_ENTITY:
922 xmlBufferWriteChar(buf, "<!ENTITY % ");
923 xmlBufferWriteCHAR(buf, ent->name);
924 if (ent->ExternalID != NULL) {
925 xmlBufferWriteChar(buf, " PUBLIC ");
926 xmlBufferWriteQuotedString(buf, ent->ExternalID);
927 xmlBufferWriteChar(buf, " ");
928 xmlBufferWriteQuotedString(buf, ent->SystemID);
930 xmlBufferWriteChar(buf, " SYSTEM ");
931 xmlBufferWriteQuotedString(buf, ent->SystemID);
933 xmlBufferWriteChar(buf, ">\n");
936 xmlEntitiesErr(XML_DTD_UNKNOWN_ENTITY,
937 "xmlDumpEntitiesDecl: internal: unknown type entity type");
942 * xmlDumpEntityDeclScan:
943 * @ent: An entity table
944 * @buf: An XML buffer.
946 * When using the hash table scan function, arguments need to be reversed
949 xmlDumpEntityDeclScan(xmlEntityPtr ent, xmlBufferPtr buf) {
950 xmlDumpEntityDecl(buf, ent);
954 * xmlDumpEntitiesTable:
955 * @buf: An XML buffer.
956 * @table: An entity table
958 * This will dump the content of the entity table as an XML DTD definition
961 xmlDumpEntitiesTable(xmlBufferPtr buf, xmlEntitiesTablePtr table) {
962 xmlHashScan(table, (xmlHashScanner)xmlDumpEntityDeclScan, buf);
964 #endif /* LIBXML_OUTPUT_ENABLED */
965 #define bottom_entities
966 #include "elfgcchack.h"