C 讀取xml檔案

2021-08-17 09:09:55 字數 865 閱讀 2637

2.將tinyxml檔案目錄下的tinystr.h、tinystr.cpp、tinyxml.h、tinyxml.cpp、tinyxmlerror.cpp、tinyxmlparser.cpp等放入工程目錄下

3.使用的xml範例如下

book store!

book1

book2

4.讀取**如下

a)申明tixmldocument 型別變數儲存xml檔案

b)申明tixmlelement指標指向元素

c)申明tixmlnode指標指向元素儲存的文字

d)value()方法返回元素名或文字

#include "tinyxml.h"

#include #include using namespace std;

void loadxml()

tixmlelement* root = doc.firstchildelement();//指向xml文件的根元素

if (root == null)//檢測根元素存在性

//elem指向根的第乙個孩子元素

for (tixmlelement* elem = root->firstchildelement(); elem != null; elem = elem->nextsiblingelement())

if (strcmp(elem->value(), "item1") == 0) }}

int main(int argc, char* argv)

5.執行結果

book store!

book2

請按任意鍵繼續. . .

以上。。。

C 讀取XML檔案

xml結構如下 c users desktop 機台資料 eventdata.txt sa5r22eb 27b4 48d7 9de9 c9df6ddf61af 1c users desktop 機台資料 eventdata.txt urh672eb 27b4 48d7 9de9 c9df6ddf61...

C 讀取大型Xml檔案

這篇部落格將介紹在c 中如何讀取資料量很大的xml檔案。請看下面的xml檔案,xml version 1.0 encoding utf 8 catalog book id bk101 author gambardella,matthew author title c developer title ...

讀取XML檔案

private void button2 click object sender,eventargs e using filestream fs new filestream filename,filemode.open,fileaccess.read n xl.name 是否有屬性 if xl.h...