TinyXML:属性

Posted lnlin

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了TinyXML:属性相关的知识,希望对你有一定的参考价值。

TiXmlAttribute:

代表XML中的属性,TiXmlAttribute中定义了一系列对属性的操作

TiXmlAttribute的友元类:

friend class TiXmlAttributeSet

TiXmlAttribute的成员函数(即对TiXmlAttribute的操作):

TiXmlAttribute();
TiXmlAttribute( const std::string& _name, const std::string& _value );
TiXmlAttribute( const char * _name, const char * _value );
// 构造一个TiXmlAttribute

const char*    Name() const    { return name.c_str(); }    
const char*    Value() const    { return value.c_str(); }
const TIXML_STRING& NameTStr() const { return name; }
const std::string& ValueStr() const    { return value; }    
// 获取TiXmlAttribute的名字和值    <Student name="value"/>

int    IntValue() const;    
double    DoubleValue() const;
// 返回属性值,并将其转化为int/double

int QueryIntValue( int* _value ) const;
int QueryDoubleValue( double* _value ) const;
// 用于检查值字符串

void SetName( const char* _name )    { name = _name; }    
void SetValue( const char* _value )    { value = _value; }    
void SetName( const std::string& _name )    { name = _name; }    
void SetValue( const std::string& _value )    { value = _value; }
// 设置属性名字/值

void SetIntValue( int _value );    
void SetDoubleValue( double _value );    
// 设置属性值,通过int/double

const TiXmlAttribute* Next() const;
// 获取此属性在DOM中后一个兄弟属性
TiXmlAttribute* Next();

const TiXmlAttribute* Previous() const;
TiXmlAttribute* Previous();
// 获取此属性在DOM中前一个兄弟属性

bool operator==( const TiXmlAttribute& rhs ) const { return rhs.name == name; }
bool operator<( const TiXmlAttribute& rhs )    const { return name < rhs.name; }
bool operator>( const TiXmlAttribute& rhs ) const { return name > rhs.name; }
// 运算符重载

virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
virtual void Print( FILE* cfile, int depth ) constvoid Print( FILE* cfile, int depth, TIXML_STRING* str ) const;
// 将属性print到一个文件流

void SetDocument( TiXmlDocument* doc )    { document = doc; }
// 设置document指针,使得属性可以报告错误

TiXmlAttributeSet:

相当于TiXmlAttribute的一个辅助类,定义了一些用于属性操作

TiXmlAttributeSet的成员函数(不过多解释,因为都可以从名字上看出相应函数的作用):

TiXmlAttributeSet();
~TiXmlAttributeSet();

void Add( TiXmlAttribute* attribute );
void Remove( TiXmlAttribute* attribute );

const TiXmlAttribute* First()    const    { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
TiXmlAttribute* First()    { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
const TiXmlAttribute* Last() const    { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
TiXmlAttribute* Last()    { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }

TiXmlAttribute*    Find( const char* _name ) const;
TiXmlAttribute* FindOrCreate( const char* _name );

 

以上是关于TinyXML:属性的主要内容,如果未能解决你的问题,请参考以下文章

使用 TinyXML 解析 XML 元素

使用tinyxml-2更新XML DOM c ++上的数据

无法打开输入文件tinyxml_STL.lib

TinyXML 解析 UTF-8 字符串的问题

使用TinyXML进行XML操作

如何计算 TinyXml 中的元素?