扩展阅读
 
当前位置:  编程语言>c/c++

ticpp(TinyXML++)TinyXML的C++封装介绍

 
    发布时间:2014-6-17  


    本文导语: ticpp(TinyXML++)TinyXML的C++封装介绍 ticpp(TinyXML++)正式名称为ticpp,ticpp是一个使用c++语言封装的全新的基于TinyXML的操作XML的库。它使用了模板,异常和错误处理。 ticpp(TinyXML++) is a completely new interface to TinyXML that use...

ticpp(tinyxml++)tinyxmlc++封装介绍


   ticpp(TinyXML++)正式名称为ticpp,ticpp是一个使用c++语言封装的全新的基于TinyXML的操作XML的库。它使用了模板异常和错误处理。

   ticpp(TinyXML++) is a completely new interface to TinyXML that uses MANY of the C++ strengths. Templates, exceptions,

and much better error handling.It is really cool because this version let's you interface tiny the exact same way as before or you can choose to use the new 'ticpp' classes. All you need to do is define TIXML_USE_TICPP. It has been tested in VC 6.0, VC 7.0, VC 7.1, VC 8.0, MinGW gcc 3.4.5, and in Linux GNU gcc 3+.


 ticpp(TinyXML++)在线文档  

 ticpp(TinyXML++)主页  

 ticpp(TinyXML++)源码SVN下载地址:  svn checkout http://ticpp.googlecode.com/svn/trunk/ ticpp-read-only


 关于TinyXML的详细介绍请参见: TinyXML介绍


  ticpp(TinyXML++)通过异常来进行容错处理具体用法代码举例:  

// Load a document
TiXmlDocument doc(pFilename);
if (!doc.LoadFile()) return;
// Make a document handle
TiXmlHandle hDoc(&doc);
// Get an element by using the handle to chain calls
// Note the conversion of the TiXmlHandle to the TiXmlElement* - .Element()
TiXmlElement* pElem = hDoc.FirstChildElement().NextSibling().Element();
if ( !pElem ) return;
// do something useful here


    ticpp(TinyXML++)
使用模板来进行自动类型转换:

try
{
 Load a document
    ticpp::Document doc( pFilename );
    doc.LoadFile();
 Get an element by chaining calls - no return values to check, no TiXmlHandle
    ticpp::Element* pElem = doc.FirstChildElement()->NextSibling();
 GetAttribute can determine the type of the pointer, and convert automatically
 Get the attribute as a string
    std::string attr;
    pElem->GetAttribute( "myAttribute", &attr );
 Get the attribute as an int
    int attr2;
    pElem->GetAttribute( "myAttribute", &attr2 );
 Get the attribute as an float
    float attr3;
    pElem->GetAttribute( "myAttribute", &attr3 );
 Get the attribute as an double
    double attr4;
    pElem->GetAttribute( "myAttribute", &attr4 );
 Get the attribute as an bool
    bool attr5;
    pElem->GetAttribute( "myAttribute", &attr5 );
}
catch( ticpp::Exception& ex )
{
 If any function has an error, execution will enter here.
 Report the error
    std::cout << ex.what();
}

    您可能感兴趣的文章:

  • 本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
    本站(WWW.)站内文章除注明原创外,均为转载,整理或搜集自网络.欢迎任何形式的转载,转载请注明出处.
    转载请注明:文章转载自:[169IT-IT技术资讯]
    本文标题:ticpp(TinyXML++)TinyXML的C++封装介绍
相关文章推荐:


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3