VC下提取XML信息
有个XML内容如下:<UserListProVer="1"DeptVer="13"><Deptid="1"Ver="7"><USERNICK="li"UIN="1003"...
有个XML内容如下:
<UserList ProVer="1" DeptVer="13">
<Dept id="1" Ver="7">
<USER NICK="li" UIN="1003"/>
</Dept>
<Dept id="2" Ver="6">
<USER NICK="qian" UIN="1002"/>
<USER NICK="zhao" UIN="1001"/>
</Dept>
<Dept id="3" Ver="13">
<USER NICK="beijing" UIN="1006"/>
</Dept>
<Dept id="4" Ver="12">
<USER NICK="shanghai" UIN="1005"/>
</Dept>
<Dept id="5" Ver="11">
<USER NICK="chengdu" UIN="1004"/>
<USER NICK="chongqing" UIN="1007"/>
</Dept>
<Dept id="199999" Ver="0"/>
</UserList>
我要提取每个Dept及其下的USER NICK后面的值及UIN后面的值,请问在VC下该怎么操作 展开
<UserList ProVer="1" DeptVer="13">
<Dept id="1" Ver="7">
<USER NICK="li" UIN="1003"/>
</Dept>
<Dept id="2" Ver="6">
<USER NICK="qian" UIN="1002"/>
<USER NICK="zhao" UIN="1001"/>
</Dept>
<Dept id="3" Ver="13">
<USER NICK="beijing" UIN="1006"/>
</Dept>
<Dept id="4" Ver="12">
<USER NICK="shanghai" UIN="1005"/>
</Dept>
<Dept id="5" Ver="11">
<USER NICK="chengdu" UIN="1004"/>
<USER NICK="chongqing" UIN="1007"/>
</Dept>
<Dept id="199999" Ver="0"/>
</UserList>
我要提取每个Dept及其下的USER NICK后面的值及UIN后面的值,请问在VC下该怎么操作 展开
3个回答
展开全部
这么点点 简单内容 自己写一个呗
给你我写的例子 你的比这个例子简单多了
http://hi.baidu.com/bluestar2012/item/098d910c3d19bbfaa1103453
WINDOWS下C语言解析XML
xml文件内容
<?xml version="1.0" encoding="UTF-8" ?>
- <aicomoa_response>
- <country_list>
- <country>
<id>7</id>
<pid>0</pid>
<continent_id>1</continent_id>
<guohao>93</guohao>
<cntitle>阿富汗</cntitle>
<entitle>Afghanistan</entitle>
<hztitle>阿富汗</hztitle>
<jptitle>アフガニスタン</jptitle>
<kotitle>??????</kotitle>
<jp_pinyin>ア</jp_pinyin>
<pinyin>AFuHan</pinyin>
<sid>0</sid>
<jibie>1</jibie>
</country>
- <country>
<id>8</id>
<pid>0</pid>
<continent_id>2</continent_id>
<guohao>355</guohao>
<cntitle>阿尔巴尼亚</cntitle>
<entitle>Albania</entitle>
<hztitle>阿尔巴尼亚</hztitle>
<jptitle>アルバニア</jptitle>
<kotitle />
<jp_pinyin>ア</jp_pinyin>
<pinyin>AErBaNiYa</pinyin>
<sid>0</sid>
<jibie>1</jibie>
</country>
</country_list>
</aicomoa_response>
运行结果
Info[0]=[id:7|pid:0|continent_id:1|guohao:93|cntitle:阿富汗|entitle:Afghanistan|
hztitle:阿富汗|jptitle:アフガニスタン|kotitle:??????|jp_pinyin:ア|pinyin:AFuHan|
sid:0|jibie:1|]
Info[1]=[id:7|pid:0|continent_id:1|guohao:93|cntitle:阿富汗|entitle:Afghanistan|
hztitle:阿富汗|jptitle:アフガニスタン|kotitle:??????|jp_pinyin:ア|pinyin:AFuHan|
sid:0|jibie:1|]
Press any key to continue
代码
#include <stdio.h>
#include <string.h>
main()
{
int i=0;
FILE *fp;
char szFileBuff[1024] = {0}, szBuff[100][1024];
char id[10] = {0}, pid[10] = {0}, continent_id[10] = {0}, guohao[10] = {0},
cntitle[64]= {0},entitle[64]= {0},hztitle[64] = {0},jptitle[64] = {0},
kotitle[64] = {0},jp_pinyin[64] = {0}, pinyin[64] = {0},sid[10] = {0},jibie[10] = {0};
char *lFirst, *lEnd;
fp = fopen("country.txt","r");
if (fp==NULL)
{
printf("read XML file error!\n");
}
while(fgets(szFileBuff, 1023, fp))
{
if ((lFirst = strstr(szFileBuff, "<id>")) != NULL)
{
lEnd = strstr(lFirst + 1, "</id>");
memcpy(id, lFirst + 4, lEnd - lFirst - 4);
}
if ((lFirst = strstr(szFileBuff, "<pid>")) != NULL)
{
lEnd = strstr(lFirst + 1, "</pid>");
memcpy(pid, lFirst + 5, lEnd - lFirst - 5);
}
if ((lFirst = strstr(szFileBuff, "<continent_id>")) != NULL)
{
lEnd = strstr(lFirst + 1, "</continent_id>");
memcpy(continent_id, lFirst + 14, lEnd - lFirst - 14);
}
if ((lFirst = strstr(szFileBuff, "<guohao>")) != NULL)
{
lEnd = strstr(lFirst + 1, "</guohao>");
memcpy(guohao, lFirst + 8, lEnd - lFirst - 8);
}
if ((lFirst = strstr(szFileBuff, "<cntitle>")) != NULL)
{
lEnd = strstr(lFirst + 1, "</cntitle>");
memcpy(cntitle, lFirst + 9, lEnd - lFirst - 9);
}
if ((lFirst = strstr(szFileBuff, "<entitle>")) != NULL)
{
lEnd = strstr(lFirst + 1, "</entitle>");
memcpy(entitle, lFirst + 9, lEnd - lFirst - 9);
}
if ((lFirst = strstr(szFileBuff, "<hztitle>")) != NULL)
{
lEnd = strstr(lFirst + 1, "</hztitle>");
memcpy(hztitle, lFirst + 9, lEnd - lFirst - 9);
}
if ((lFirst = strstr(szFileBuff, "<jptitle>")) != NULL)
{
lEnd = strstr(lFirst + 1, "</jptitle>");
memcpy(jptitle, lFirst + 9, lEnd - lFirst - 9);
}
if ((lFirst = strstr(szFileBuff, "<kotitle>")) != NULL)
{
lEnd = strstr(lFirst + 1, "</kotitle>");
memcpy(kotitle, lFirst + 9, lEnd - lFirst - 9);
}
if ((lFirst = strstr(szFileBuff, "<jp_pinyin>")) != NULL)
{
lEnd = strstr(lFirst + 1, "</jp_pinyin>");
memcpy(jp_pinyin, lFirst + 11, lEnd - lFirst - 11);
}
if ((lFirst = strstr(szFileBuff, "<pinyin>")) != NULL)
{
lEnd = strstr(lFirst + 1, "</pinyin>");
memcpy(pinyin, lFirst + 8, lEnd - lFirst - 8);
}
if ((lFirst = strstr(szFileBuff, "<sid>")) != NULL)
{
lEnd = strstr(lFirst + 1, "</sid>");
memcpy(sid, lFirst + 5, lEnd - lFirst - 5);
}
if ((lFirst = strstr(szFileBuff, "<jibie>")) != NULL)
{
lEnd = strstr(lFirst + 1, "</jibie>");
memcpy(jibie, lFirst + 7, lEnd - lFirst - 7);
}
if ((lFirst = strstr(szFileBuff, "</country>")) != NULL)
{
sprintf(szBuff[i],"id:%s|pid:%s|continent_id:%s|guohao:%s|cntitle:%s|entitle:%s|hztitle:%s|jptitle:%s|kotitle:%s|jp_pinyin:%s|pinyin:%s|sid:%s|jibie:%s|",
id,pid,continent_id,guohao,cntitle,entitle,hztitle,jptitle,kotitle,jp_pinyin, pinyin,sid,jibie);
printf("Info[%d]=[%s]\n",i++, szBuff);
}
}
fclose(fp);
}
更多追问追答
追问
这个是处理的无属性XML,带属性的该怎么处理啊?
追答
什么叫无属性 有属性? 就是字符串 和 数值的 区别吗?
取出来自己转换啊 不要告诉我你不会啊
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
用tinyXML吧,开源的哦!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-06-05
展开全部
CMarkup类
追问
能给出具体代码不 我现在只能查到二级
xml.FindElem("UserList");
xml.FindChildElem("Dept");
查三级时就出问题了
xml.FindChildElem("USER");
这句话是查找失败的 能不能提供下具体的代码 灰常感谢
追答
xml.FindElem("UserList");
xml.IntoElem();
xml.FindElem("Dept");
xml.IntoElem();
xml.FindElem("USER");//这样试试
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询