#include"stdio.h"
#include<libxml/parser.h>
#include<libxml/tree.h>
#include<libxml/xmlmemory.h>
int main()
{
xmlDocPtr doc;
        xmlNodePtr cur,root,childcur;
        xmlChar* key;
char* xmlfile = "xx1.xml";
        doc = xmlParseFile(xmlfile);
if(doc == NULL)
{
  fprintf(stderr,"not parserfile");
}
       
root = xmlDocGetRootElement(doc);
if(root == NULL)
{
fprintf(stderr,"not root");
xmlFreeDoc(doc);
}
       
if(xmlStrcmp(root->name,(const xmlChar*)"root"))
{
 
xmlFreeDoc(doc);
fprintf(stderr,"not root");
}
cur = root->xmlChildrenNode;
        while(cur != NULL)
{
if(!xmlStrcmp(cur->name,(const xmlChar*)"datasource"))
        {
key = xmlGetProp(cur,"name");
printf("%s\n",(char *)key);
childcur = cur->xmlChildrenNode;
while(childcur != NULL)
{
if(!xmlStrcmp(childcur->name,(const xmlChar*)"dataitem"))
{
key = xmlGetProp(childcur,"name");
printf("%s\n",(char*)key);
}
childcur = childcur->next;
}
 
        }
  cur = cur->next;
}
return 0;
}
 
 
gcc -g -I  /usr/local/include/libxml2  -lxml2  xml.c -o xml
 
1 linux 读取xml。
2 gcc编译。