core dump on xmlStrcmp

Johan den Boer

Usenet Archive
Joined
Feb 23, 2003
Messages
6
Reaction score
0
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; }

}
 

Langelage Frank

Usenet Archive
Joined
Sep 26, 2003
Messages
1
Reaction score
0
Johan said:
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 took your code and tried this on my machine (SunBlade 150, Solaris 9, libxml2-2.4.23). Everything works like expected: name = "story" !

Breakpoint 1, parseDoc (docname=0x10a10 "test.xml") at test.c:26 26 if (xmlStrcmp(cur->name, (const xmlChar *) "story")) { (gdb) p *cur $2 = {_private = 0x0, type = XML_ELEMENT_NODE, name = 0x20fa0 "story", children = 0x34a88, last = 0x34c08, parent = 0x349f0, next = 0x0, prev = 0x0, doc = 0x349f0, ns = 0x0, content = 0x0, properties = 0x0, nsDef = 0x0} (gdb)

What's the version of your libxml ?

Regards - Frank
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,208
Messages
3,104,802
Members
249,594
Latest member
henrywalsh

Latest Threads

Top