以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 XML工具及XML开发环境 』  (http://bbs.xml.org.cn/list.asp?boardid=7)
----  一个关于libXML解析的问题  (http://bbs.xml.org.cn/dispbbs.asp?boardid=7&rootid=&id=48159)


--  作者:versace0922
--  发布时间:6/7/2007 5:17:00 PM

--  一个关于libXML解析的问题
我写了一个解析xml的c程序,但是运行的时候出现以下的错误,libxml我已经在机器上安装了,系统是linux的,请各位大虾帮帮忙,谢谢了。
parseXml.c:4:30: error: libxml/xmlmemory.h: No such file or directory
parseXml.c:5:28: error: libxml/parser.h: No such file or directory

--  作者:versace0922
--  发布时间:6/7/2007 5:20:00 PM

--  
代码如下:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>

void parse(xmlDocPtr doc, xmlNodePtr cur)
{
 xmlChar *key;
 cur = cur->xmlChildrenNode;
 while (cur != NULL) {
  if((!xmlStrcmp(cur->name, (const xmlChar *)"port"))) {
   key = xmlNodeListGetString(doc,cur->xmlChildrenNode,1);
   printf("port: %s\n",key);
   xmlFree(key);
  }
  cur = cur->next;
 }
 return;
}

static void parseDoc(char *docname) {
 xmlDocPtr doc;
 xmlNodePtr cur;

 doc = xmlParseFile("xunlei.xml");

 if(doc == NULL) {
  fprintf(stderr,"Document not parsed successfully. \n");
  return;
 }

 cur = xmlDocGetRootElement(doc);
 printf("the root is :", cur);

 if(cur == NULL) {
  fprintf(stderr, "empty document \n");
  xmlFreeDoc(doc);
  return;
 }

 if(xmlStrcmp(cur->name, (const xmlChar *) "xunlei")) {
  fprintf(stderr,"document of the wrong type,root node != xunlei");
  xmlFreeDoc(doc);
  return;
 }

 cur = cur->xmlChildrenNode;
 while(cur != NULL) {
  if((!xmlStrcmp(cur->name,(const xmlChar *)"tcp"))) {
   parse(doc,cur);
  }
 cur = cur->next;
 }
 xmlFreeDoc(doc);
 return;
}

int main(int argc,char **argv) {
 char *docname;
 if(argc <= 1) {
  printf("Usage: %s document \n",argv[0]);
  return(0);
 }
 docname = argv[1];
 parseDoc(docname);

 return(1);
}


--  作者:xmllf
--  发布时间:8/26/2007 3:39:00 PM

--  
libxml已经在机器上安装了???参照以下命令编译
g++ aa.cpp -o aa -I $(HOME)/libxml2/include/libxml2/  -L $(HOME)/libxml2/lib/ -lxml2
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
46.875ms