--- entities.c 2002/01/24 15:02:46 1.57 +++ entities.c 2002/01/26 15:04:19 @@ -363,6 +363,47 @@ } /** + * xmlGetEntityFromDtd: + * @dtd: A pointer to the DTD to search + * @name: The entity name + * + * Do an entity lookup in the DTD entity hash table and + * return the corresponding entity, if found. + * + * Returns A pointer to the entity structure or NULL if not found. + */ +xmlEntityPtr +xmlGetEntityFromDtd(xmlDtdPtr dtd, const xmlChar *name) { + xmlEntitiesTablePtr table; + + if((dtd != NULL) && (dtd->entities != NULL)) { + table = (xmlEntitiesTablePtr) dtd->entities; + return(xmlGetEntityFromTable(table, name)); + } + return(NULL); +} +/** + * xmlGetParameterEntityFromDtd: + * @dtd: A pointer to the DTD to search + * @name: The entity name + * + * Do an entity lookup in the DTD pararmeter entity hash table and + * return the corresponding entity, if found. + * + * Returns A pointer to the entity structure or NULL if not found. + */ +xmlEntityPtr +xmlGetParameterEntityFromDtd(xmlDtdPtr dtd, const xmlChar *name) { + xmlEntitiesTablePtr table; + + if ((dtd != NULL) && (dtd->pentities != NULL)) { + table = (xmlEntitiesTablePtr) dtd->pentities; + return(xmlGetEntityFromTable(table, name)); + } + return(NULL); +} + +/** * xmlGetDocEntity: * @doc: the document referencing the entity * @name: the entity name @@ -883,6 +924,8 @@ cur->content = xmlStrdup(ent->content); if (ent->orig != NULL) cur->orig = xmlStrdup(ent->orig); + if (ent->URI != NULL) + cur->URI = xmlStrdup(ent->URI); return(cur); } diff -u -r1.185 tree.c --- tree.c 2002/01/24 16:05:41 1.185 +++ tree.c 2002/01/26 15:04:19 @@ -1821,8 +1821,6 @@ if (tree == NULL) return; - if (tree->type == XML_ENTITY_DECL) - return; if (tree->doc != doc) { if(tree->type == XML_ELEMENT_NODE) { prop = tree->properties; @@ -2989,8 +2987,10 @@ q->doc = doc; q->parent = parent; doc->intSubset = (xmlDtdPtr) q; + xmlAddChild(parent, q); } else { q = (xmlNodePtr) doc->intSubset; + xmlAddChild(parent, q); } } else q = xmlStaticCopyNode(node, doc, parent, 1); @@ -3067,6 +3067,7 @@ xmlDtdPtr xmlCopyDtd(xmlDtdPtr dtd) { xmlDtdPtr ret; + xmlNodePtr cur, p = NULL, q; if (dtd == NULL) return(NULL); ret = xmlNewDtd(NULL, dtd->name, dtd->ExternalID, dtd->SystemID); @@ -3083,6 +3084,60 @@ if (dtd->attributes != NULL) ret->attributes = (void *) xmlCopyAttributeTable( (xmlAttributeTablePtr) dtd->attributes); + if (dtd->pentities != NULL) + ret->pentities = (void *) xmlCopyEntitiesTable( + (xmlEntitiesTablePtr) dtd->pentities); + + cur = dtd->children; + while (cur != NULL) { + q = NULL; + + if (cur->type == XML_ENTITY_DECL) { + xmlEntityPtr tmp = (xmlEntityPtr) cur; + switch (tmp->etype) { + case XML_INTERNAL_GENERAL_ENTITY: + case XML_EXTERNAL_GENERAL_PARSED_ENTITY: + case XML_EXTERNAL_GENERAL_UNPARSED_ENTITY: + q = (xmlNodePtr) xmlGetEntityFromDtd(ret, tmp->name); + break; + case XML_INTERNAL_PARAMETER_ENTITY: + case XML_EXTERNAL_PARAMETER_ENTITY: + q = (xmlNodePtr) + xmlGetParameterEntityFromDtd(ret, tmp->name); + break; + case XML_INTERNAL_PREDEFINED_ENTITY: + break; + } + } else if (cur->type == XML_ELEMENT_DECL) { + xmlElementPtr tmp = (xmlElementPtr) cur; + q = (xmlNodePtr) + xmlGetDtdQElementDesc(ret, tmp->name, tmp->prefix); + } else if (cur->type == XML_ATTRIBUTE_DECL) { + xmlAttributePtr tmp = (xmlAttributePtr) cur; + q = (xmlNodePtr) + xmlGetDtdQAttrDesc(ret, tmp->elem, tmp->name, tmp->prefix); + } else if (cur->type == XML_COMMENT_NODE) { + q = xmlCopyNode(cur, 0); + } + + if (q == NULL) { + cur = cur->next; + continue; + } + + if (p == NULL) + ret->children = q; + else + p->next = q; + + q->prev = p; + q->parent = (xmlNodePtr) ret; + q->next = NULL; + ret->last = q; + p = q; + cur = cur->next; + } + return(ret); } @@ -3116,7 +3171,7 @@ ret->children = NULL; if (doc->intSubset != NULL) { ret->intSubset = xmlCopyDtd(doc->intSubset); - ret->intSubset->doc = ret; + xmlSetTreeDoc((xmlNodePtr)ret->intSubset, ret); ret->intSubset->parent = ret; } if (doc->oldNs != NULL) --- include/libxml/entities.h 2001/12/31 16:16:02 1.31 +++ include/libxml/entities.h 2002/01/26 15:04:20 @@ -38,8 +38,8 @@ void *_private; /* application data */ xmlElementType type; /* XML_ENTITY_DECL, must be second ! */ const xmlChar *name; /* Attribute name */ - struct _xmlNode *children; /* NULL */ - struct _xmlNode *last; /* NULL */ + struct _xmlNode *children; /* First child link */ + struct _xmlNode *last; /* Last child link */ struct _xmlDtd *parent; /* -> DTD */ struct _xmlNode *next; /* next sibling link */ struct _xmlNode *prev; /* previous sibling link */ @@ -86,7 +86,12 @@ const xmlChar *name); xmlEntityPtr xmlGetDtdEntity (xmlDocPtr doc, const xmlChar *name); +xmlEntityPtr xmlGetEntityFromDtd (xmlDtdPtr dtd, + const xmlChar *name); xmlEntityPtr xmlGetParameterEntity (xmlDocPtr doc, + const xmlChar *name); +xmlEntityPtr xmlGetParameterEntityFromDtd + (xmlDtdPtr dtd, const xmlChar *name); const xmlChar * xmlEncodeEntities (xmlDocPtr doc, const xmlChar *input);