Compare two XMLNodes in C (libxml library)

1.4k views Asked by At

I'm parsing some xml files in C using libxml library. I want to compare two xmlnodes to see whether they contain the same data or not. Is there any function available to do so?

2

There are 2 answers

0
simonc On BEST ANSWER

The libxml API docs seem reasonable and suggest that xmlBufGetNodeContent and xmlBufContent might do what you want.

xmlNode node1, node2;
......
xmlBuf buf;
xmlChar* content1 = NULL;
xmlChar* content2 = NULL;
if (xmlBufGetNodeContent(&buf, &node1) == 0) {
    content1 = xmlBufContent(&buf);
}
if (xmlBufGetNodeContent(&buf, &node2) == 0) {
    content2 = xmlBufContent(&buf);
}
if (strcmp(content1, content2) == 0) {
    /* nodes match */
}
0
siddharth On

I don't think the api calls xmlBufGetNodeContent and xmlBufContent are any more valid. As the datatype involved in those calls - xmlBufPtr are no more available , atleast not on libxml2 2.7.6 I used a different api call xmlNodeDump or xmlNodeGetContent. hope it helps others with similar question.