现在的位置: 首页 > 综合 > 正文

Symbian中使用XML库

2013年07月07日 ⁄ 综合 ⁄ 共 677字 ⁄ 字号 评论关闭

    SymbianOS自带XML解析库,是基于SAX的解析,但需要自己组织内存的分配。虽然SAX可以有效的节约内存,常用于解析大型的XML,但使用起来太麻烦了。这里介绍使用开源的XML库:TinyXml。

  下载地址:www.sourceforge.net/projects/tinyxml,下载TinyXml的源码。

  调用方法:

#include "TinyXML.h"
// 解析XML
void CMoinView::LoadXmlL()
{
 static const char * KXmlFile = "c://Private//eb51b2b9//fs.xml";
 TiXmlDocument* doc = new TiXmlDocument(KXmlFile);
 CleanupStack::PushL(doc);

 doc->LoadFile();

 const TiXmlElement* root = doc->RootElement();

 for( const TiXmlNode* child = root->FirstChild();
  child;
  child=child->NextSibling())
 {
  ShowTextL(child->Value(), ETrue);
 }
 doc->Clear();

// 注意此处不能使用 PopAndDestroy(doc),
// TiXmlDocument并非继承于CBase,
// 使用PopAndDestroy,doc将会被以void*的类型被delete。
 CleanupStack::Pop(doc);  
 delete doc;
}

抱歉!评论已关闭.