* xmlCopyDtd: * @dtd: the DTD * * Copy a DTD. * * Returns the copied DTD or NULL if a memory allocation failed. */
| 4548 | * Returns the copied DTD or NULL if a memory allocation failed. |
| 4549 | */ |
| 4550 | xmlDtdPtr |
| 4551 | xmlCopyDtd(xmlDtdPtr dtd) { |
| 4552 | xmlDtdPtr ret; |
| 4553 | xmlNodePtr cur, p = NULL, q; |
| 4554 | |
| 4555 | if (dtd == NULL) return(NULL); |
| 4556 | ret = xmlNewDtd(NULL, dtd->name, dtd->ExternalID, dtd->SystemID); |
| 4557 | if (ret == NULL) return(NULL); |
| 4558 | if (dtd->entities != NULL) { |
| 4559 | ret->entities = (void *) xmlCopyEntitiesTable( |
| 4560 | (xmlEntitiesTablePtr) dtd->entities); |
| 4561 | if (ret->entities == NULL) |
| 4562 | goto error; |
| 4563 | } |
| 4564 | if (dtd->notations != NULL) { |
| 4565 | ret->notations = (void *) xmlCopyNotationTable( |
| 4566 | (xmlNotationTablePtr) dtd->notations); |
| 4567 | if (ret->notations == NULL) |
| 4568 | goto error; |
| 4569 | } |
| 4570 | if (dtd->elements != NULL) { |
| 4571 | ret->elements = (void *) xmlCopyElementTable( |
| 4572 | (xmlElementTablePtr) dtd->elements); |
| 4573 | if (ret->elements == NULL) |
| 4574 | goto error; |
| 4575 | } |
| 4576 | if (dtd->attributes != NULL) { |
| 4577 | ret->attributes = (void *) xmlCopyAttributeTable( |
| 4578 | (xmlAttributeTablePtr) dtd->attributes); |
| 4579 | if (ret->attributes == NULL) |
| 4580 | goto error; |
| 4581 | } |
| 4582 | if (dtd->pentities != NULL) { |
| 4583 | ret->pentities = (void *) xmlCopyEntitiesTable( |
| 4584 | (xmlEntitiesTablePtr) dtd->pentities); |
| 4585 | if (ret->pentities == NULL) |
| 4586 | goto error; |
| 4587 | } |
| 4588 | |
| 4589 | cur = dtd->children; |
| 4590 | while (cur != NULL) { |
| 4591 | q = NULL; |
| 4592 | |
| 4593 | if (cur->type == XML_ENTITY_DECL) { |
| 4594 | xmlEntityPtr tmp = (xmlEntityPtr) cur; |
| 4595 | switch (tmp->etype) { |
| 4596 | case XML_INTERNAL_GENERAL_ENTITY: |
| 4597 | case XML_EXTERNAL_GENERAL_PARSED_ENTITY: |
| 4598 | case XML_EXTERNAL_GENERAL_UNPARSED_ENTITY: |
| 4599 | q = (xmlNodePtr) xmlGetEntityFromDtd(ret, tmp->name); |
| 4600 | break; |
| 4601 | case XML_INTERNAL_PARAMETER_ENTITY: |
| 4602 | case XML_EXTERNAL_PARAMETER_ENTITY: |
| 4603 | q = (xmlNodePtr) |
| 4604 | xmlGetParameterEntityFromDtd(ret, tmp->name); |
| 4605 | break; |
| 4606 | case XML_INTERNAL_PREDEFINED_ENTITY: |
| 4607 | break; |
no test coverage detected