C14N: default attributes not added
According to https://www.w3.org/TR/2001/REC-xml-c14n-20010315 the default attributes must be added to an element. However, the following C code:
#include <stdio.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <libxml/c14n.h>
static int visible(void *, xmlNodePtr, xmlNodePtr) {
return 1;
}
int main() {
xmlDocPtr doc = xmlReadFile("example.xml", NULL, 0);
if (doc == NULL) {
fprintf(stderr, "Failed to parse the XML document.\n");
return 1;
}
// C14N actual code
xmlOutputBufferPtr buf = xmlAllocOutputBuffer(NULL);
int result = xmlC14NExecute(doc, visible, doc->children, 0, NULL, 0, buf);
if (result < 0) {
fprintf(stderr, "Failed to perform canonicalization.\n");
return 1;
}
// Get & print the canonicalized XML content from the buffer
const xmlChar* c14nXml = xmlOutputBufferGetContent(buf);
printf("Canonicalized XML:\n%s\n", c14nXml);
xmlOutputBufferClose(buf);
xmlFreeDoc(doc);
return 0;
}
With this example.xml file:
<?xml version="1.0"?>
<!DOCTYPE doc [
<!ATTLIST temp attr CDATA "default">
]>
<doc xmlns="">
<temp xmlns=""/>
</doc>
Results in:
xmlCanonicalized XML:
<doc>
<temp></temp>
</doc>
But I expected:
xmlCanonicalized XML:
<doc>
<temp attr="default"></temp>
</doc>