Regression in 2.12.0: xmlCopyDoc doesn't copy DTD anymore
The following code:
#include <stdio.h>
#include <libxml/parser.h>
int main() {
const char xml[] = "<!DOCTYPE foo [<!ENTITY x \"hi\">]><foo>&x;</foo>";
xmlDocPtr doc = xmlReadMemory(xml, sizeof(xml)-1, NULL, NULL, 0);
if (doc == NULL) {
fprintf(stderr, "Failed to parse document\n");
return 1;
}
xmlDocPtr copy = xmlCopyDoc(doc, 1);
xmlSaveFormatFileEnc("-", copy, "UTF-8", 1);
xmlFreeDoc(doc);
xmlFreeDoc(copy);
return 0;
}
Outputs this in version 2.11.6 and below:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [
<!ENTITY x "hi">
]>
<foo>&x;</foo>
but in 2.12 it outputs:
<?xml version="1.0" encoding="UTF-8"?>
<foo>&x;</foo>
It seems to me this is a regression as I couldn't find a NEWS entry saying this is intentional. The documentation also says of xmlDocCopy: "Do a copy of the document info. If recursive, the content tree will be copied too as well as DTD, namespaces and entities." So I believe it should copy the DTD.
Thanks in advance
Edited by Niels Dossche