diff --git a/ChangeLog b/ChangeLog index 1b22e90d..69a281b6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Thu Dec 13 23:19:50 CET 2001 Daniel Veillard + + * valid.c: fix the xmlStrdup() used in the previous patch. + * valid.c: added --dropdtd + * tree.c: fixed xmlUnlinkNode so it also removes the references + from the document if the node is a DTD + Thu Dec 13 15:54:35 CET 2001 Daniel Veillard * HTMLtree.c valid.c: cleanup some static declarations diff --git a/tree.c b/tree.c index 56a11a17..9d0bc9a5 100644 --- a/tree.c +++ b/tree.c @@ -2486,6 +2486,14 @@ xmlUnlinkNode(xmlNodePtr cur) { #endif return; } + if (cur->type == XML_DTD_NODE) { + xmlDocPtr doc; + doc = cur->doc; + if (doc->intSubset == (xmlDtdPtr) cur) + doc->intSubset = NULL; + if (doc->extSubset == (xmlDtdPtr) cur) + doc->extSubset = NULL; + } if ((cur->parent != NULL) && (cur->parent->children == cur)) cur->parent->children = cur->next; if ((cur->parent != NULL) && (cur->parent->last == cur)) diff --git a/xmllint.c b/xmllint.c index b44bf48b..07c828c7 100644 --- a/xmllint.c +++ b/xmllint.c @@ -112,6 +112,7 @@ static int loaddtd = 0; static int progresult = 0; static int timing = 0; static int generate = 0; +static int dropdtd = 0; static struct timeval begin, end; #ifdef LIBXML_CATALOG_ENABLED static int catalogs = 0; @@ -373,13 +374,20 @@ xmlShellReadline(char *prompt) { return (line_read); #else char line_read[501]; + char *ret; + int len; if (prompt != NULL) fprintf(stdout, "%s", prompt); if (!fgets(line_read, 500, stdin)) return(NULL); line_read[500] = 0; - return((char *) xmlStrdup((xmlChar *) line_read)); + len = strlen(line_read); + ret = (char *) malloc(len + 1); + if (ret != NULL) { + memcpy (ret, line_read, len + 1); + } + return(ret); #endif } @@ -601,6 +609,19 @@ static void parseAndPrintFile(char *filename) { fprintf(stderr, "Parsing took %ld ms\n", msec); } + /* + * Remove DOCTYPE nodes + */ + if (dropdtd) { + xmlDtdPtr dtd; + + dtd = xmlGetIntSubset(doc); + if (dtd != NULL) { + xmlUnlinkNode((xmlNodePtr)dtd); + xmlFreeDtd(dtd); + } + } + #ifdef LIBXML_XINCLUDE_ENABLED if (xinclude) { if ((timing) && (!repeat)) { @@ -866,6 +887,7 @@ static void usage(const char *name) { #endif printf("\t--loaddtd : fetch external Dtd\n"); printf("\t--dtdattr : loaddtd + populate the tree with inherited attributes \n"); + printf("\t--dropdtd : remove the DOCTYPE of the input docs\n"); } int main(int argc, char **argv) { @@ -945,6 +967,9 @@ main(int argc, char **argv) { dtdvalid = argv[i]; loaddtd++; } + else if ((!strcmp(argv[i], "-dropdtd")) || + (!strcmp(argv[i], "--dropdtd"))) + dropdtd++; else if ((!strcmp(argv[i], "-insert")) || (!strcmp(argv[i], "--insert"))) insert++;