當前位置:成語大全網 - 書法字典 - 如何用C語言解析xml文件

如何用C語言解析xml文件

我上次剛寫給某人。

Xml文件內容

& lt?xml版本=“1.0“編碼=“UTF-8“?& gt

-& lt;aicomoa _ response & gt

-& lt;國家/地區列表& gt

-& lt;國家& gt

& ltid & gt7 & lt/id & gt;

& ltpid & gt0 & lt/PID & gt;

& ltcontinental _ id & gt;1 & lt;/continental _ id & gt;

& lt國浩& gt93 & lt/國浩& gt

& ltcnttitle & gt;阿富汗

& lt題為& gt阿富汗</entitle & gt;

& lthztitle & gt阿富汗

& ltjptitle & gtアフガニスタン<;/jp title & gt;

& ltkotitle & gt& lt/kotitle & gt;

& ltjp _ pinyin & gtア<;/jp _ pinyin & gt;

& lt拼音& gt阿福漢& lt/拼音& gt

& ltsid & gt0 & lt/sid & gt;

& ltjibie & gt1 & lt;/jibie & gt;

& lt/country & gt;

-& lt;國家& gt

& ltid & gt8 & lt/id & gt;

& ltpid & gt0 & lt/PID & gt;

& ltcontinental _ id & gt;2 & lt/continental _ id & gt;

& lt國浩& gt355 & lt/國浩& gt

& ltcnttitle & gt;阿爾巴尼亞

& lt題為& gt阿爾巴尼亞</entitle & gt;

& lthztitle & gt阿爾巴尼亞

& ltjptitle & gtアルバニア<;/jp title & gt;

& ltkotitle/& gt;

& ltjp _ pinyin & gtア<;/jp _ pinyin & gt;

& lt拼音& gt阿爾巴尼耶& lt/拼音& gt

& ltsid & gt0 & lt/sid & gt;

& ltjibie & gt1 & lt;/jibie & gt;

& lt/country & gt;

& lt/country _ list & gt;

& lt/aico moa _ response & gt;

運行結果

info【0】=【ID:7 | PID:0 | continental _ ID:1 |國浩:93 | cn標題:阿富汗|標題:阿富汗|

Hztitle:阿富汗| JP title: ァフガニスタン| Ko title: | JP _拼音:ァ|拼音:阿富漢|

sid:0|jibie:1|】

info【1】=【ID:7 | PID:0 | continental _ ID:1 |國浩:93 | cn標題:阿富汗|標題:阿富汗|

Hztitle:阿富汗| JP title: ァフガニスタン| Ko title: | JP _拼音:ァ|拼音:阿富漢|

sid:0|jibie:1|】

按任意鍵繼續

密碼

# include & ltstdio.h & gt

# include & ltstring.h & gt

主()

{

int I = 0;

FILE * fp

char SZ file buff【1024】= { 0 },SZ buff【100】【1024】;

char id【10】= { 0 },PID【10】= { 0 },continental _ id【10】= { 0 },國浩【10】= { 0 }

cnttitle【64】= { 0 },entitle【64】= { 0 },Hz title【64】= { 0 },jp title【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(“讀取XML文件錯誤!\ n ");

}

while(fgets(szFileBuff,1023,fp))

{

if((lFirst = strstr(szFileBuff,“& ltid & gt”)) != NULL)

{

lEnd = str str(lFirst+1,“& lt/id & gt;”);

memcpy(id,lFirst + 4,lEnd-l first-4);

}

if((lFirst = strstr(szFileBuff,“& ltpid》了)) != NULL)

{

lEnd = str str(lFirst+1,“& lt/PID & gt;”);

memcpy(PID,lFirst + 5,lEnd-l first-5);

}

if((lFirst = strstr(szFileBuff,“& ltcontinental _ id & gt;”)) != NULL)

{

lEnd = str str(lFirst+1,“& lt/continental _ id & gt;”);

memcpy(continental _ id,lFirst + 14,lEnd-l first-14);

}

if((lFirst = strstr(szFileBuff,“& lt國浩》)) != NULL)

{

lEnd = str str(lFirst+1,“& lt/國浩》);

memcpy(國浩,lFirst + 8,lEnd-l first-8);

}

if((lFirst = strstr(szFileBuff,“& ltcntitle》)) != NULL)

{

lEnd = str str(lFirst+1,“& lt/cnttitle & gt;”);

memcpy(cntitle,lFirst + 9,lEnd-l first-9);

}

if((lFirst = strstr(szFileBuff,“& lt題為》)) != NULL)

{

lEnd = str str(lFirst+1,“& lt/entitle & gt;”);

memcpy(entitle,lFirst + 9,lEnd-l first-9);

}

if((lFirst = strstr(szFileBuff,“& lthztitle》)) != NULL)

{

lEnd = str str(lFirst+1,“& lt/Hz title & gt;”);

memcpy(Hz title,lFirst + 9,lEnd-l first-9);

}

if((lFirst = strstr(szFileBuff,“& ltjptitle》)) != NULL)

{

lEnd = str str(lFirst+1,“& lt/jptitle>);

memcpy(jp title,lFirst + 9,lEnd-l first-9);

}

if((lFirst = strstr(szFileBuff,“& ltkotitle》)) != NULL)

{

lEnd = str str(lFirst+1,“& lt/kotitle>);

memcpy(kotitle,lFirst + 9,lEnd-l first-9);

}

if((lFirst = strstr(szFileBuff,“& ltjp _拼音》)) != NULL)

{

lEnd = str str(lFirst+1,“& lt/jp_pinyin>);

memcpy(jp _ pinyin,lFirst + 11,lEnd-l first-11);

}

if((lFirst = strstr(szFileBuff,“& lt拼音》)) != NULL)

{

lEnd = str str(lFirst+1,“& lt/拼音》);

memcpy(拼音,lFirst + 8,lEnd-l first-8);

}

if((lFirst = strstr(szFileBuff,“& ltsid》gt;”)) != NULL)

{

lEnd = str str(lFirst+1,“& lt/sid & gt;);

memcpy(sid,lFirst + 5,lEnd-l first-5);

}

if((lFirst = strstr(szFileBuff,“& ltjibie》)) != NULL)

{

lEnd = str str(lFirst+1,“& lt/jibie & gt;”);

memcpy(jibie,lFirst + 7,lEnd-l first-7);

}

if((lFirst = strstr(szFileBuff,“& lt/country》)) != NULL)

{

sprintf(SZ buff【I】,“id:% s | PID:% s | continental _ id:% s |國浩:% s | cnttitle:% s | entitle:% s | Hz title:% s | jp title:% s | kotitle:% s | jp _ pinyin:% s | pinyin:% s | sid:% s | jibie:% s |“,

id,pid,continent _ id,國浩,cntitle,entitle,hztitle,jptitle,kotitle,jp_pinyin,拼音,sid,jibie);

printf(“Info【% d】=【% s】\ n“,i++,SZ buff);

}

}

fclose(FP);

}

補充:妳太籠統了,

1您上傳的xml文件的具體格式是什麽?

網頁上顯示的具體格式是什麽?

妳根本不知道怎麽做,所以妳不知道怎麽問

我不用關心妳在C語言中的cgi,對嗎?我不在乎它是用什麽上傳的。

只有您提到的單詞embedded給了我壹些有用的信息,也就是說,恐怕無法用插件解析這個xml

只有c語言

現在我只問妳的xml文件格式和從xml解析的什麽信息應該顯示在網頁上。

只要我知道這壹點,我只需要將生成的html文件添加到我的程序中。