牵着老婆满街逛

严以律己,宽以待人. 三思而后行.
GMail/GTalk: yanglinbo#google.com;
MSN/Email: tx7do#yahoo.com.cn;
QQ: 3 0 3 3 9 6 9 2 0 .

TinyXML教程

TinyXML 是一個小巧的 C++ XML parser Library,十分容易就可以整合到你的程式,而且學習曲線十分的短。

TiXmlNode

TinyXML 使用 node 的觀念來看待 XML 文件樹,TiXmlNode 就是代表著一個節點的 class。

Load and Save

TinyXML 使用 TiXmlDocument 這個 class 來載入/儲存 xml file。A document binds together all the XML pieces. It can be saved, loaded, and printed to the screen.

TiXmlDocument doc;doc.Load( "myfile.xml" );

存取的時候,要先取得下一層的 Child Element:

TiXmlElement* element = doc.FirstChildElement();

也可以指定標籤來取得特定的 Element,如同下面的例子:

TiXmlElement* element = doc.FirstChildElement("Node");

TiXmlElement

The element is a container class. It has a value, the element name, and can contain other elements, text, comments, and unknowns. Elements also contain an arbitrary number of attributes.
<foo>This is text</foo>

例如上面的片斷,我們可以使用 GetText() 取得被包起來的文字:
const char* str = fooElement->GetText();

TinyXML and wxWidgets

TinyXML 預設以 UTF-8 編碼,wxWidgets 編譯成 Unicode mode 時,傳入的參數需要轉碼,wxString 可以使用 mb_str() 轉碼,就可以與 TinyXML一起使用。

如果要轉換 UTF-8 char * 字串為 wxString,使用下列的方式:

const char* str = fooElement->GetText();wxString myString(str, wxConvUTF8);

posted on 2006-04-24 12:14 杨粼波 阅读(5195) 评论(0)  编辑 收藏 引用 所属分类: 文章收藏


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理