免费注册 查看新帖 |

Chinaunix

广告
  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 6976 | 回复: 8
打印 上一主题 下一主题

linux 如何解析xml [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-05-05 14:32 |只看该作者 |倒序浏览
linux 下解析xml的库有哪些啊, 哪些是c 的,哪些是c++的啊,请指教啊

论坛徽章:
0
2 [报告]
发表于 2010-05-05 14:36 |只看该作者
我用的,c的
  1. xml2-config --cflags --libs
  2. -I/usr/include/libxml2
  3. -L/usr/lib -lxml2 -lz -lm
复制代码

论坛徽章:
0
3 [报告]
发表于 2010-05-05 15:13 |只看该作者
libxml2

论坛徽章:
0
4 [报告]
发表于 2010-05-05 15:24 |只看该作者
简单的parse,不验证的话,tinyxml最好了

论坛徽章:
0
5 [报告]
发表于 2010-05-05 16:59 |只看该作者
libxml

论坛徽章:
0
6 [报告]
发表于 2010-05-06 09:04 |只看该作者
  1.   
  2.   1 #include <stdlib.h>
  3.   2 #include <stdio.h>
  4.   3 #include <string.h>
  5.   4 #include <libxml2/libxml/xmlmemory.h>
  6.   5 #include <libxml2/libxml/parser.h>
  7.   6

  8.   7 int main()
  9.   8 {
  10.   9     char* ptr = "<?xml             version=\"1.0\" encoding=\"UTF-8\"?><response server=\"com.ctfo.lbs.servic    e.datamanager.UserAccountManager\"><data type=\"addUserAccount\"><SysSpOperator result=\"0\" msg=\"添加成功!
  11.     \" /></data></response>";
  12. 10
  13. 11     int len = strlen(ptr);
  14. 12
  15. 13     xmlDocPtr pdoc;
  16. 14
  17. 15     pdoc = xmlParseMemory(ptr, len);
  18. 16     if ( NULL == pdoc )
  19. 17     {
  20. 18         printf("xmlParseMemory failed!\n");
  21. 19         return 0;
  22. 20     }
  23. 21
  24. 22     xmlNodePtr root = xmlDocGetRootElement(pdoc);
  25. 23     if ( NULL == root )
  26. 24     {
  27. 25         printf("xmlDocGetRootElement failed!\n");
  28. 26         return 0;
  29. 27     }
  30. 28
  31. 29     xmlNodePtr child_node = root->xmlChildrenNode;
  32. 30     if ( NULL == child_node )
  33. 31     {
  34. 32         printf("child_node is NULL\n");
  35. 33         return 0;
  36. 34     }
  37. 35
  38. 36     xmlChar* xml_ptr = xmlGetProp(child_node, "type");
  39. 37     if ( NULL == xml_ptr )
  40. 38     {
  41. 39         printf("xmlGetProp failed!\n");
  42. 40         return 0;
  43. 41     }
  44. 42
  45. 43     printf("server's content:%s\n", xml_ptr);
  46. 44
  47. 45
复制代码

论坛徽章:
0
7 [报告]
发表于 2010-05-06 09:52 |只看该作者
这是为什么啊, 是我装的包的问题吗

[root@wgplin mnt]# find / -name xmlversion.h
/usr/include/libxml2/libxml/xmlversion.h
这是我运行的命令

/usr/include/libxml2/libxml/xmlmemory.h:16:31: 错误:libxml/xmlversion.h:没有那个文件或目录
In file included from xml.c:4:
/usr/include/libxml2/libxml/xmlmemory.h:57: 错误:expected ‘)’ before ‘*’ token
/usr/include/libxml2/libxml/xmlmemory.h:66: 错误:expected declaration specifiers or ‘...’ before numeric constant
/usr/include/libxml2/libxml/xmlmemory.h:66: 错误:expected ‘)’ before ‘XMLCALL’
/usr/include/libxml2/libxml/xmlmemory.h:77: 错误:expected ‘)’ before ‘*’ token
/usr/include/libxml2/libxml/xmlmemory.h:87: 错误:expected ‘)’ before ‘*’ token
/usr/include/libxml2/libxml/xmlmemory.h:103: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘int’
/usr/include/libxml2/libxml/xmlmemory.h:108: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘int’
/usr/include/libxml2/libxml/xmlmemory.h:113: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘int’
/usr/include/libxml2/libxml/xmlmemory.h:119: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘int’
/usr/include/libxml2/libxml/xmlmemory.h:129: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘int’
/usr/include/libxml2/libxml/xmlmemory.h:135: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
/usr/include/libxml2/libxml/xmlmemory.h:140: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘int’
/usr/include/libxml2/libxml/xmlmemory.h:142: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘int’
/usr/include/libxml2/libxml/xmlmemory.h:144: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
/usr/include/libxml2/libxml/xmlmemory.h:146: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
/usr/include/libxml2/libxml/xmlmemory.h:148: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
/usr/include/libxml2/libxml/xmlmemory.h:150: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
/usr/include/libxml2/libxml/xmlmemory.h:152: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
/usr/include/libxml2/libxml/xmlmemory.h:154: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
/usr/include/libxml2/libxml/xmlmemory.h:156: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
/usr/include/libxml2/libxml/xmlmemory.h:158: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘char’
/usr/include/libxml2/libxml/xmlmemory.h:160: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
/usr/include/libxml2/libxml/xmlmemory.h:162: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
/usr/include/libxml2/libxml/xmlmemory.h:164: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
/usr/include/libxml2/libxml/xmlmemory.h:166: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘char’
/usr/include/libxml2/libxml/xmlmemory.h:218:28: 错误:libxml/threads.h:没有那个文件或目录
/usr/include/libxml2/libxml/xmlmemory.h:219:28: 错误:libxml/globals.h:没有那个文件或目录
在包含自 xml.c:5 的文件中:
/usr/include/libxml2/libxml/parser.h:16:25: 错误:libxml/tree.h:没有那个文件或目录
/usr/include/libxml2/libxml/parser.h:17:25: 错误:libxml/dict.h:没有那个文件或目录
/usr/include/libxml2/libxml/parser.h:18:25: 错误:libxml/hash.h:没有那个文件或目录
/usr/include/libxml2/libxml/parser.h:19:26: 错误:libxml/valid.h:没有那个文件或目录
/usr/include/libxml2/libxml/parser.h:20:29: 错误:libxml/entities.h:没有那个文件或目录
/usr/include/libxml2/libxml/parser.h:21:29: 错误:libxml/xmlerror.h:没有那个文件或目录
/usr/include/libxml2/libxml/parser.h:22:30: 错误:libxml/xmlstring.h:没有那个文件或目录
In file included from xml.c:5:
/usr/include/libxml2/libxml/parser.h:52: 错误:expected ‘)’ before ‘*’ token
/usr/include/libxml2/libxml/parser.h:56: 错误:expected specifier-qualifier-list before ‘xmlParserInputBufferPtr’
/usr/include/libxml2/libxml/parser.h:187: 错误:expected specifier-qualifier-list before ‘xmlDocPtr’
/usr/include/libxml2/libxml/parser.h:313: 错误:expected ‘:’, ‘,’, ‘;’, ‘}’ or ‘__attribute__’ before ‘*’ token
/usr/include/libxml2/libxml/parser.h:341: 错误:expected declaration specifiers or ‘...’ before ‘*’ token
/usr/include/libxml2/libxml/parser.h:342: 错误:expected ‘;’, ‘,’ or ‘)’ before ‘*’ token
/usr/include/libxml2/libxml/parser.h:354: 错误:expected ‘;’, ‘,’ or ‘)’ before ‘*’ token
/usr/include/libxml2/libxml/parser.h:367: 错误:expected ‘;’, ‘,’ or ‘)’ before ‘*’ token
/usr/include/libxml2/libxml/parser.h:379: 错误:expected declaration specifiers or ‘...’ before ‘*’ token
/usr/include/libxml2/libxml/parser.h:380: 错误:expected ‘;’, ‘,’ or ‘)’ before ‘*’ token
/usr/include/libxml2/libxml/parser.h:390: 错误:expected declaration specifiers or ‘...’ before ‘*’ token
/usr/include/libxml2/libxml/parser.h:391: 错误:expected ‘;’, ‘,’ or ‘)’ before ‘*’ token
/usr/include/libxml2/libxml/parser.h:404: 错误:expected ‘;’, ‘,’ or ‘)’ before ‘*’ token
/usr/include/libxml2/libxml/parser.h:419: 错误:expected ‘;’, ‘,’ or ‘)’ before ‘*’ token
/usr/include/libxml2/libxml/parser.h:435: 错误:expected ‘;’, ‘,’ or ‘)’ before ‘*’ token
/usr/include/libxml2/libxml/parser.h:451: 错误:expected ‘;’, ‘,’ or ‘)’ before ‘*’ token
/usr/include/libxml2/libxml/parser.h:465: 错误:expected ‘;’, ‘,’ or ‘)’ before ‘*’ token
/usr/include/libxml2/libxml/parser.h:478: 错误:expected declaration specifiers or ‘...’ before ‘xmlSAXLocatorPtr’
/usr/include/libxml2/libxml/parser.h:502: 错误:expected ‘;’, ‘,’ or ‘)’ before ‘*’ token
/usr/include/libxml2/libxml/parser.h:512: 错误:expected ‘;’, ‘,’ or ‘)’ before ‘*’ token
/usr/include/libxml2/libxml/parser.h:525: 错误:expected ‘;’, ‘,’ or ‘)’ before ‘*’ token
/usr/include/libxml2/libxml/parser.h:535: 错误:expected ‘;’, ‘,’ or ‘)’ before ‘*’ token
/usr/include/libxml2/libxml/parser.h:545: 错误:expected ‘;’, ‘,’ or ‘)’ before ‘*’ token
/usr/include/libxml2/libxml/parser.h:557: 错误:expected ‘;’, ‘,’ or ‘)’ before ‘*’ token
/usr/include/libxml2/libxml/parser.h:568: 错误:expected ‘;’, ‘,’ or ‘)’ before ‘*’ token
/usr/include/libxml2/libxml/parser.h:578: 错误:expected ‘;’, ‘,’ or ‘)’ before ‘*’ token
/usr/include/libxml2/libxml/parser.h:589: 错误:expected ‘;’, ‘,’ or ‘)’ before ‘*’ token
/usr/include/libxml2/libxml/parser.h:599: 错误:expected ‘)’ before ‘*’ token
/usr/include/libxml2/libxml/parser.h:609: 错误:expected ‘)’ before ‘*’ token
/usr/include/libxml2/libxml/parser.h:621: 错误:expected ‘)’ before ‘*’ token
/usr/include/libxml2/libxml/parser.h:684: 错误:expected ‘;’, ‘,’ or ‘)’ before ‘*’ token
/usr/include/libxml2/libxml/parser.h:705: 错误:expected ‘;’, ‘,’ or ‘)’ before ‘*’ token
/usr/include/libxml2/libxml/parser.h:711: 错误:expected specifier-qualifier-list before ‘internalSubsetSAXFunc’
/usr/include/libxml2/libxml/parser.h:752: 错误:expected specifier-qualifier-list before ‘internalSubsetSAXFunc’
/usr/include/libxml2/libxml/parser.h:793: 错误:expected declaration specifiers or ‘...’ before ‘*’ token
/usr/include/libxml2/libxml/parser.h:795: 错误:expected declaration specifiers or ‘...’ before ‘xmlParserCtxtPtr’
/usr/include/libxml2/libxml/parser.h:795: 错误:‘xmlParserInputPtr’声明为返回一个函数的函数
/usr/include/libxml2/libxml/parser.h:801:29: 错误:libxml/encoding.h:没有那个文件或目录
/usr/include/libxml2/libxml/parser.h:802:26: 错误:libxml/xmlIO.h:没有那个文件或目录
/usr/include/libxml2/libxml/parser.h:813: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
/usr/include/libxml2/libxml/parser.h:815: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
/usr/include/libxml2/libxml/parser.h:821: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘int’
/usr/include/libxml2/libxml/parser.h:824: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘int’
/usr/include/libxml2/libxml/parser.h:840: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘int’
/usr/include/libxml2/libxml/parser.h:842: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘int’
/usr/include/libxml2/libxml/parser.h:844: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
/usr/include/libxml2/libxml/parser.h:846: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘int’
/usr/include/libxml2/libxml/parser.h:848: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘int’
/usr/include/libxml2/libxml/parser.h:867: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘int’
/usr/include/libxml2/libxml/parser.h:869: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘int’
/usr/include/libxml2/libxml/parser.h:934: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘xmlParserErrors’
/usr/include/libxml2/libxml/parser.h:958: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘int’
/usr/include/libxml2/libxml/parser.h:967: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘xmlParserCtxtPtr’
/usr/include/libxml2/libxml/parser.h:969: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘int’
/usr/include/libxml2/libxml/parser.h:971: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
/usr/include/libxml2/libxml/parser.h:973: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
/usr/include/libxml2/libxml/parser.h:981: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘xmlParserCtxtPtr’
/usr/include/libxml2/libxml/parser.h:1022: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘xmlParserCtxtPtr’
/usr/include/libxml2/libxml/parser.h:1030: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘xmlParserInputPtr’
/usr/include/libxml2/libxml/parser.h:1038: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘const’
/usr/include/libxml2/libxml/parser.h:1041: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
/usr/include/libxml2/libxml/parser.h:1043: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
/usr/include/libxml2/libxml/parser.h:1045: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘unsigned’
/usr/include/libxml2/libxml/parser.h:1048: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
/usr/include/libxml2/libxml/parser.h:1056: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
/usr/include/libxml2/libxml/parser.h:1058: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘xmlExternalEntityLoader’
/usr/include/libxml2/libxml/parser.h:1060: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘xmlParserInputPtr’
/usr/include/libxml2/libxml/parser.h:1068: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘long’
/usr/include/libxml2/libxml/parser.h:1106: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
/usr/include/libxml2/libxml/parser.h:1108: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘int’
/usr/include/libxml2/libxml/parser.h:1114: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘int’
/usr/include/libxml2/libxml/parser.h:1117: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘xmlDocPtr’
/usr/include/libxml2/libxml/parser.h:1122: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘xmlDocPtr’
/usr/include/libxml2/libxml/parser.h:1126: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘xmlDocPtr’
/usr/include/libxml2/libxml/parser.h:1132: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘xmlDocPtr’
/usr/include/libxml2/libxml/parser.h:1137: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘xmlDocPtr’
/usr/include/libxml2/libxml/parser.h:1144: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘xmlDocPtr’
/usr/include/libxml2/libxml/parser.h:1150: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘xmlDocPtr’
/usr/include/libxml2/libxml/parser.h:1155: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘xmlDocPtr’
/usr/include/libxml2/libxml/parser.h:1162: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘xmlDocPtr’
/usr/include/libxml2/libxml/parser.h:1168: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘xmlDocPtr’
/usr/include/libxml2/libxml/parser.h:1222: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘int’

论坛徽章:
0
8 [报告]
发表于 2010-05-06 09:57 |只看该作者
回复 7# wang_guang_ping


    gcc中+上 -I/usr/include/libxml2/ -lxml2

论坛徽章:
0
9 [报告]
发表于 2010-05-06 10:27 |只看该作者
谢谢啊
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP