日期:2014-05-16 浏览次数:20685 次
int xml_parse(char *buf,int size, int index)
{
int i,len,id;
xmlDocPtr doc;
xmlNodePtr curNode;
doc = xmlParseMemory(buf,size);
if (doc == NULL)
{
fprintf(stderr,"Document not parsed successfully.\n");
return -1;
}
curNode = xmlDocGetRootElement(doc); // get root element
if (NULL == curNode)
{
fprintf(stderr,"empty document.\n");
xmlFreeDoc(doc);
return -1;
}
if (xmlStrcmp(curNode->name, BAD_CAST "root"))
{
fprintf(stderr,"document of the wrong type, root node != root");
xmlFreeDoc(doc);
return -1;
}
curNode = curNode->xmlChildrenNode; // get first child
while(curNode != NULL)
{
if(!xmlStrcmp(curNode->name, BAD_CAST "heart_beat"))
{
//heart beat handle
curNode = curNode->children;
while(curNode != NULL)
{
if(0 == xmlStrcmp(curNode->name,(const xmlChar *) "time"))
{
char *content = (char *)xmlNodeListGetString(doc,curNode->xmlChildrenNode,1);
if(content)
{
printf("recv notify...\n");
xmlFree(content);
}
break;