怎么用c语言解析xml文件
答案:3 悬赏:10
解决时间 2021-03-04 01:46
- 提问者网友:咪咪
- 2021-03-03 04:12
怎么用c语言解析xml文件
最佳答案
- 二级知识专家网友:鸠书
- 2021-03-03 04:24
我上次才给人写过
xml文件内容
-
-
-
7
0
1
93
阿富汗
Afghanistan
阿富汗
アフガニスタン
??????
ア
AFuHan
0
1
-
8
0
2
355
阿尔巴尼亚
Albania
阿尔巴尼亚
アルバニア
ア
AErBaNiYa
0
1
运行结果
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
#include
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, "")) != NULL)
{
lEnd = strstr(lFirst + 1, " ");
memcpy(id, lFirst + 4, lEnd - lFirst - 4);
}
if ((lFirst = strstr(szFileBuff, "")) != NULL)
{
lEnd = strstr(lFirst + 1, " ");
memcpy(pid, lFirst + 5, lEnd - lFirst - 5);
}
if ((lFirst = strstr(szFileBuff, "")) != NULL)
{
lEnd = strstr(lFirst + 1, " ");
memcpy(continent_id, lFirst + 14, lEnd - lFirst - 14);
}
if ((lFirst = strstr(szFileBuff, "")) != NULL)
{
lEnd = strstr(lFirst + 1, " ");
memcpy(guohao, lFirst + 8, lEnd - lFirst - 8);
}
if ((lFirst = strstr(szFileBuff, "")) != NULL)
{
lEnd = strstr(lFirst + 1, " ");
memcpy(cntitle, lFirst + 9, lEnd - lFirst - 9);
}
if ((lFirst = strstr(szFileBuff, "")) != NULL)
{
lEnd = strstr(lFirst + 1, " ");
memcpy(entitle, lFirst + 9, lEnd - lFirst - 9);
}
if ((lFirst = strstr(szFileBuff, "")) != NULL)
{
lEnd = strstr(lFirst + 1, " ");
memcpy(hztitle, lFirst + 9, lEnd - lFirst - 9);
}
if ((lFirst = strstr(szFileBuff, "")) != NULL)
{
lEnd = strstr(lFirst + 1, " ");
memcpy(jptitle, lFirst + 9, lEnd - lFirst - 9);
}
if ((lFirst = strstr(szFileBuff, "")) != NULL)
{
lEnd = strstr(lFirst + 1, " ");
memcpy(kotitle, lFirst + 9, lEnd - lFirst - 9);
}
if ((lFirst = strstr(szFileBuff, "")) != NULL)
{
lEnd = strstr(lFirst + 1, " ");
memcpy(jp_pinyin, lFirst + 11, lEnd - lFirst - 11);
}
if ((lFirst = strstr(szFileBuff, "")) != NULL)
{
lEnd = strstr(lFirst + 1, " ");
memcpy(pinyin, lFirst + 8, lEnd - lFirst - 8);
}
if ((lFirst = strstr(szFileBuff, "")) != NULL)
{
lEnd = strstr(lFirst + 1, " ");
memcpy(sid, lFirst + 5, lEnd - lFirst - 5);
}
if ((lFirst = strstr(szFileBuff, "")) != NULL)
{
lEnd = strstr(lFirst + 1, " ");
memcpy(jibie, lFirst + 7, lEnd - lFirst - 7);
}
if ((lFirst = strstr(szFileBuff, "")) != 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);
}
补充:你这个就说得太笼统了,
1 你上传的xml文件具体格式是什么?
2 要在网页上显示的具体格式是什么
3 你根本不知道怎么做 所以也不知道怎么问
我不用关心你的c语言的cgi吧?我才不管是用什么上传的
只有你说的嵌入式三个字 给我一点有用信息 就是解析这个xml用插件恐怕是不行
只能C语言
4 我现在只要求你的xml文件格式和 网页上要显示哪些xml中解析出来的信息
只要知道这些 我只需要在我的程序上加上生成html文件就行了追问就是上传.xml格式的文件 在html上显示.xml文件的内容追答看来你真不懂
我上面贴的你看懂了么?
我问的是你xml文件里内容的格式
如果不明白 能不能把你的xml文件给我发一份
我写个程序 保证你一运行就能生成一个带有xml中信息的html文件追问
content of node 1
node has attributes
other way to create content
追答第一 xml文件你没贴完整,所以文件格式不完整
第二 你的html网页上要显示xml中的哪些节点内容
其实我上面贴的例子已经很明显了
也是先贴了xml文件内容
然后贴了 提取出来的内容
再下面是代码 你这个只不过是要把显示的写入html文件而已追问先写个网页用post的方法把xml文件上传到arm上的web服务器上然后服务器返回xml文件的内容,上传文件的网页好些,但是cgi怎么写才能将xml文件的内容解析出来??哥们我说明白吗??追答我明白 我就没考虑怎么做那个上传
我现在就是妖你xml的完整内容格式 你明白么?
把xml全贴上来 或者发给我
我也不问你要html显示什么了
我把我抓出来的都用表格显示好了
话说你有Q么? 这样说很累
xml文件内容
-
-
-
-
运行结果
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
#include
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, "
{
lEnd = strstr(lFirst + 1, "
memcpy(id, lFirst + 4, lEnd - lFirst - 4);
}
if ((lFirst = strstr(szFileBuff, "
{
lEnd = strstr(lFirst + 1, "
memcpy(pid, lFirst + 5, lEnd - lFirst - 5);
}
if ((lFirst = strstr(szFileBuff, "
{
lEnd = strstr(lFirst + 1, "
memcpy(continent_id, lFirst + 14, lEnd - lFirst - 14);
}
if ((lFirst = strstr(szFileBuff, "
{
lEnd = strstr(lFirst + 1, "
memcpy(guohao, lFirst + 8, lEnd - lFirst - 8);
}
if ((lFirst = strstr(szFileBuff, "
{
lEnd = strstr(lFirst + 1, "
memcpy(cntitle, lFirst + 9, lEnd - lFirst - 9);
}
if ((lFirst = strstr(szFileBuff, "
{
lEnd = strstr(lFirst + 1, "
memcpy(entitle, lFirst + 9, lEnd - lFirst - 9);
}
if ((lFirst = strstr(szFileBuff, "
{
lEnd = strstr(lFirst + 1, "
memcpy(hztitle, lFirst + 9, lEnd - lFirst - 9);
}
if ((lFirst = strstr(szFileBuff, "
{
lEnd = strstr(lFirst + 1, "
memcpy(jptitle, lFirst + 9, lEnd - lFirst - 9);
}
if ((lFirst = strstr(szFileBuff, "
{
lEnd = strstr(lFirst + 1, "
memcpy(kotitle, lFirst + 9, lEnd - lFirst - 9);
}
if ((lFirst = strstr(szFileBuff, "
{
lEnd = strstr(lFirst + 1, "
memcpy(jp_pinyin, lFirst + 11, lEnd - lFirst - 11);
}
if ((lFirst = strstr(szFileBuff, "
{
lEnd = strstr(lFirst + 1, "
memcpy(pinyin, lFirst + 8, lEnd - lFirst - 8);
}
if ((lFirst = strstr(szFileBuff, "
{
lEnd = strstr(lFirst + 1, "
memcpy(sid, lFirst + 5, lEnd - lFirst - 5);
}
if ((lFirst = strstr(szFileBuff, "
{
lEnd = strstr(lFirst + 1, "
memcpy(jibie, lFirst + 7, lEnd - lFirst - 7);
}
if ((lFirst = strstr(szFileBuff, "")) != 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);
}
补充:你这个就说得太笼统了,
1 你上传的xml文件具体格式是什么?
2 要在网页上显示的具体格式是什么
3 你根本不知道怎么做 所以也不知道怎么问
我不用关心你的c语言的cgi吧?我才不管是用什么上传的
只有你说的嵌入式三个字 给我一点有用信息 就是解析这个xml用插件恐怕是不行
只能C语言
4 我现在只要求你的xml文件格式和 网页上要显示哪些xml中解析出来的信息
只要知道这些 我只需要在我的程序上加上生成html文件就行了追问就是上传.xml格式的文件 在html上显示.xml文件的内容追答看来你真不懂
我上面贴的你看懂了么?
我问的是你xml文件里内容的格式
如果不明白 能不能把你的xml文件给我发一份
我写个程序 保证你一运行就能生成一个带有xml中信息的html文件追问
第二 你的html网页上要显示xml中的哪些节点内容
其实我上面贴的例子已经很明显了
也是先贴了xml文件内容
然后贴了 提取出来的内容
再下面是代码 你这个只不过是要把显示的写入html文件而已追问先写个网页用post的方法把xml文件上传到arm上的web服务器上然后服务器返回xml文件的内容,上传文件的网页好些,但是cgi怎么写才能将xml文件的内容解析出来??哥们我说明白吗??追答我明白 我就没考虑怎么做那个上传
我现在就是妖你xml的完整内容格式 你明白么?
把xml全贴上来 或者发给我
我也不问你要html显示什么了
我把我抓出来的都用表格显示好了
话说你有Q么? 这样说很累
全部回答
- 1楼网友:鱼芗
- 2021-03-03 05:34
推荐使用libxml2,专门解析xml文件的opensource library
- 2楼网友:琴狂剑也妄
- 2021-03-03 04:58
直接打开 支持的
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯
• 手机登qq时,显示手机磁盘不足,清理后重新登 |
• 刺客的套装怎么选啊? |