要解析的xml原始檔
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
12345
下面開始解析...看原始碼...這個最直接了哈...
nsstring *strxml = [ nsstring stringwithcontentsoffile:@"/mtctest.xml" encoding:nsutf8stringencoding error:nil];
const char* chxml = [strxml utf8string];
tixmldocument* xmldocument = new tixmldocument;
xmldocument->parse(chxml);
//declaration
tixmlnode* pxmlfirst = xmldocument->firstchild();
tixmldeclaration* pxmldec = pxmlfirst->todeclaration();
if (null != pxmldec)
//colour
tixmlelement* colourelement = xmldocument->rootelement();
const char* colourvalue = colourelement->value();
nslog(@"colour*****=%s",colourvalue);
//header
tixmlelement *headerelement = colourelement->firstchildelement();
const char* headervalue = headerelement->value();
const char* headertext = headerelement->gettext();
nslog(@"header*****=%s,%s",headervalue,headertext);
//item
tixmlelement *itemelement = headerelement->nextsiblingelement();
const char* itemvalue1 = itemelement->value();
tixmlattribute* itemattribute = itemelement->firstattribute();
const char* itemname = itemattribute->name();
const char* itemvalue = itemattribute->value();
nslog(@"item*****=%s,%s,%s",itemvalue1,itemname,itemvalue);
//text
tixmlelement *textelement = itemelement->firstchildelement();
const char* textvalue1 = textelement->value();
tixmlattribute* textattribute = textelement->firstattribute();
const char* textname = textattribute->name();
const char* textvalue = textattribute->value();
nslog(@"text*****=%s,%s,%s",textvalue1,textname,textvalue);
好.下面看控制台的輸出結果
2010-07-09 15:55:25.369 myxmltest[8227:207] declaration*****=1.0,utf-8,yes
2010-07-09 15:55:25.371 myxmltest[8227:207] colour*****=colour
2010-07-09 15:55:25.372 myxmltest[8227:207] header*****=header,12345
2010-07-09 15:55:25.372 myxmltest[8227:207] item*****=item,type,abcd
2010-07-09 15:55:25.373 myxmltest[8227:207] text*****=text,value,00000000
怎麼樣...夠簡單的吧...想要什麼直接拿就行了...
tinyxml官網:http://www.grinninglizard.com/tinyxml/index.html
tinyxml在wince下的用法
1.包含xml解析類檔案頭 include tinyxml.h 2.定義變數 tixmldocument m pxml bool m bloadxml 3.讀函式 bool calarmdlg readcfgfile flag true 記憶體 if m pxml null return flag ...
iphone 下AsyncSocket網路庫程式設計
phone的標準推薦cfnetworkc庫程式設計.但是程式設計比較煩躁。在其它os往往用類來封裝的對socket函式的處理。比如mfc的casysncsocket.在iphone也有類似於開源專案.cocoaasyncsocket庫 官方 它用來簡化cfnetwork的呼叫.一.在專案引入asyn...
Linux下將Tinyxml編譯為靜態庫
04 using namespace std 05 06 int main 07 建立test.xml檔案,內容如下 view sourceprint?01 02 03 周星星04 2005 06 07 白晶晶08 1809 10 編譯當前檔案,呼叫libtinyxml.a庫 root server...