- #include<stdio.h>
- #include<string.h>
- #include<stdlib.h>
- #include<libxml/xmlmemory.h>
- #include<libxml/parser.h>
- #include<libxml/tree.h>
- void
- get_connnectrequestUrl(char*docname){
- xmlDocPtrdoc;
- xmlNodePtrcur;
- doc=xmlParseFile(docname);
- if(doc==NULL){
- printf("Documentnotparsedsuccessfully.\n");
- return;
- }
- cur=xmlDocGetRootElement(doc);
- if(cur==NULL){
- printf("emptydocument\n");
- xmlFreeDoc(doc);
- if(xmlStrcmp(cur->name,(constxmlChar*)"Context")){
- printf("documentofthewrongtype,rootnode!=Context");
- xmlFreeDoc(doc);
- return;
- }
- cur=cur->xmlChildrenNode;
- while(cur!=NULL){
- xmlNodePtrcur2_tmp=cur;
- xmlChar*key;
- xmlChar*attr;
- charconnectrequestUrl[32];
- if((!xmlStrcmp(cur->name,153); font-weight:bold; background-color:inherit">constxmlChar*)"list"))){
- attr=xmlNodeListGetString(doc,cur->properties->xmlChildrenNode,1);
- if((!xmlStrcmp(attr,153); font-weight:bold; background-color:inherit">constxmlChar*)"rrm_cell"))){
- xmlFree(attr);
- cur=cur->xmlChildrenNode;
- constxmlChar*)"item"))){
- attr=xmlNodeListGetString(doc,1);
- constxmlChar*)"Cell_Map_s"))){
- xmlFree(attr);
- while(cur!=NULL){
- xmlNodePtrcur2_tmp=cur;
- constxmlChar*)"p"))){
- constxmlChar*)"Hnb_IP"))){
- printf("********************\n");
- key=xmlNodeListGetString(doc,cur->xmlChildrenNode,248)"> memcpy(connectrequestUrl,(constchar*)key,strlen((char*)key));
- connectrequestUrl[strlen((char*)key)]='\0';
- printf("theurlis:%s\n",connectrequestUrl);
- xmlFree(key);
- else{
- /*resetcul*/
- cur=cur2_tmp;
- cur=cur->next;
- /*RESETcur*/
- else{
- cur=cur2_tmp;
- cur=cur->next;
- intmain(void){
- while(1){
- get_connnectrequestUrl("config.xml");
- sleep(5);
- //return0;
编译:gcc -o testxml4 testxml4.c -I /usr/local/include/libxml2/ -L /usr/local/lib -lxml2
使用valgrind检测内存泄露的情况:valgrind--tool=memcheck--leak-check=full./testxml4
交叉编译:arm-none-linux-gnueabi-gcc -o testxml4 testxml4.c -I /usr/local/include/libxml2/ -L /usr/local/lib -lxml2