J
Johan den Boer
Hi
I tried the code below ( parseDoc ) on my xml file ( see below ) but this
gives me a core dump on xmlStrcmp function. It seems that cur->name is a
NULL pointer. cur->contents has the value 'story'.
What am I doing wrong ?
xml file
<?xml version="1.0"?>
<story>
<storyinfo>
<author>Some author</author>
</storyinfo>
</story>
void parseDoc( char *docname )
{
xmlDocPtr doc;
xmlNodePtr cur;
doc = xmlParseFile(docname);
if (doc == NULL ) {
fprintf(stderr,"Document not parsed successfully. \n");
return;
}
cur = xmlDocGetRootElement(doc);
if (cur == NULL) {
fprintf(stderr,"empty document\n");
xmlFreeDoc(doc);
return;
}
// Next function call gives core dump because cur->name is NULL pointer
if (xmlStrcmp(cur->name, (const xmlChar *) "story")) {
fprintf(stderr,"document of the wrong type, root node != story");
xmlFreeDoc(doc);
return;
}
}
I tried the code below ( parseDoc ) on my xml file ( see below ) but this
gives me a core dump on xmlStrcmp function. It seems that cur->name is a
NULL pointer. cur->contents has the value 'story'.
What am I doing wrong ?
xml file
<?xml version="1.0"?>
<story>
<storyinfo>
<author>Some author</author>
</storyinfo>
</story>
void parseDoc( char *docname )
{
xmlDocPtr doc;
xmlNodePtr cur;
doc = xmlParseFile(docname);
if (doc == NULL ) {
fprintf(stderr,"Document not parsed successfully. \n");
return;
}
cur = xmlDocGetRootElement(doc);
if (cur == NULL) {
fprintf(stderr,"empty document\n");
xmlFreeDoc(doc);
return;
}
// Next function call gives core dump because cur->name is NULL pointer
if (xmlStrcmp(cur->name, (const xmlChar *) "story")) {
fprintf(stderr,"document of the wrong type, root node != story");
xmlFreeDoc(doc);
return;
}
}