| 6687 | */ |
| 6688 | |
| 6689 | int |
| 6690 | xmlValidateDocument(xmlValidCtxtPtr ctxt, xmlDocPtr doc) { |
| 6691 | int ret; |
| 6692 | xmlNodePtr root; |
| 6693 | |
| 6694 | if (doc == NULL) |
| 6695 | return(0); |
| 6696 | if ((doc->intSubset == NULL) && (doc->extSubset == NULL)) { |
| 6697 | xmlErrValid(ctxt, XML_DTD_NO_DTD, |
| 6698 | "no DTD found!\n", NULL); |
| 6699 | return(0); |
| 6700 | } |
| 6701 | if ((doc->intSubset != NULL) && ((doc->intSubset->SystemID != NULL) || |
| 6702 | (doc->intSubset->ExternalID != NULL)) && (doc->extSubset == NULL)) { |
| 6703 | xmlChar *sysID; |
| 6704 | if (doc->intSubset->SystemID != NULL) { |
| 6705 | sysID = xmlBuildURI(doc->intSubset->SystemID, |
| 6706 | doc->URL); |
| 6707 | if (sysID == NULL) { |
| 6708 | xmlErrValid(ctxt, XML_DTD_LOAD_ERROR, |
| 6709 | "Could not build URI for external subset \"%s\"\n", |
| 6710 | (const char *) doc->intSubset->SystemID); |
| 6711 | return 0; |
| 6712 | } |
| 6713 | } else |
| 6714 | sysID = NULL; |
| 6715 | doc->extSubset = xmlParseDTD(doc->intSubset->ExternalID, |
| 6716 | (const xmlChar *)sysID); |
| 6717 | if (sysID != NULL) |
| 6718 | xmlFree(sysID); |
| 6719 | if (doc->extSubset == NULL) { |
| 6720 | if (doc->intSubset->SystemID != NULL) { |
| 6721 | xmlErrValid(ctxt, XML_DTD_LOAD_ERROR, |
| 6722 | "Could not load the external subset \"%s\"\n", |
| 6723 | (const char *) doc->intSubset->SystemID); |
| 6724 | } else { |
| 6725 | xmlErrValid(ctxt, XML_DTD_LOAD_ERROR, |
| 6726 | "Could not load the external subset \"%s\"\n", |
| 6727 | (const char *) doc->intSubset->ExternalID); |
| 6728 | } |
| 6729 | return(0); |
| 6730 | } |
| 6731 | } |
| 6732 | |
| 6733 | if (doc->ids != NULL) { |
| 6734 | xmlFreeIDTable(doc->ids); |
| 6735 | doc->ids = NULL; |
| 6736 | } |
| 6737 | if (doc->refs != NULL) { |
| 6738 | xmlFreeRefTable(doc->refs); |
| 6739 | doc->refs = NULL; |
| 6740 | } |
| 6741 | ret = xmlValidateDtdFinal(ctxt, doc); |
| 6742 | if (!xmlValidateRoot(ctxt, doc)) return(0); |
| 6743 | |
| 6744 | root = xmlDocGetRootElement(doc); |
| 6745 | ret &= xmlValidateElement(ctxt, doc, root); |
| 6746 | ret &= xmlValidateDocumentFinal(ctxt, doc); |
no test coverage detected