日期:2014-05-16 浏览次数:21025 次
#include <stdio.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
void xmlNodeWalk(xmlNodePtr node)
{
xmlChar *data;
while (NULL != node) {
if (NULL == node->xmlChildrenNode
|| XML_TEXT_NODE == node->xmlChildrenNode->type) {
data = xmlNodeGetContent(node);
printf("[%s][%s]\n", node->name, data);
xmlFree(data);
} else {
xmlNodeWalk(node->xmlChildrenNode);
}
node = node->next;
}
}
int main(int argc, char *argv[])
{
xmlDocPtr doc;
xmlNodePtr root;
xmlKeepBlanksDefault(0);
doc = xmlParseFile("demo.xml");
root = xmlDocGetRootElement(doc);
xmlNodeWalk(root);
xmlFreeDoc(doc);
return 0;
}