ticpp(tinyxml++)tinyxml的c++封装介绍
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();
}