|
libxml c
i have xml file like this
Code:
<root>
<sree>
<cnu value="cprogramming"\>
</sree>
</root>
to retrieve the valuse of cnu element i tried the following code
Code:
Code:
void
parseDoc() {
xmlDocPtr doc;
xmlNodePtr cur;
doc = xmlParseFile("/usr/share/1.xml");
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;
}
cur = cur->xmlChildrenNode;
while (cur != NULL) {
if ((!xmlStrcmp(cur->name, (const xmlChar *)"sree"))){
parseStory (doc, cur);
}
cur = cur->next;
}
}
void
parseStory (xmlDocPtr doc, xmlNodePtr cur) {
xmlChar *key;
cur = cur->xmlChildrenNode;
while (cur != NULL) {
if ((!xmlStrcmp(cur->name, (const xmlChar *)"cnu "))) {
cur->name = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
printf("keyword: %s\n",cur->name);
//xmlFree();
}
cur = cur->next;
}
return;
}
BUT my problem is when i print the value
iam getting null .
how can i retrieve the dataaa
thank u
sreee
Last edited by vino; 04-23-2007 at 03:05 AM..
Reason: Please put your code within the codetags.
|