TinyXML是目前非常流行的一款基于DOM模型的XML解析器,简单易用且小巧玲珑,非常适合存储简单数据,配置文件,对象序列化等数据量不是很大的操作,其主页是:http://www.grinninglizard.com/tinyxml/,目前最新版本是2_6_2。
TinyXml总体包含如下几个类
下面逐一进行描述。
1.TiXmlBase
描述: 在 TinyXml 中,它是所有类的父类
公有函数:
<span style="font-family:SimSun;font-size:14px;"><span style="font-family:Microsoft YaHei;font-size:14px;">virtual void Print(FILE *cfile, int depth) const = 0; </span></span>
<span style="font-family:SimSun;font-size:14px;"><span style="font-family:Microsoft YaHei;font-size:14px;">int Row() const
int Column() const
void SetUserData(void *user)</span></span>
<span style="font-family:SimSun;font-size:14px;"><span style="font-family:Microsoft YaHei;font-size:14px;">void * GetUserData()
const void * GetUserData() const</span></span>
静态公有函数
<span style="font-family:SimSun;font-size:14px;"><span style="font-family:Microsoft YaHei;font-size:14px;">static void SetCondenseWhiteSpace(bool condense)
static bool IsWhiteSpaceCondensed()
static void EncodeString(const TIXML_STRING&str, TIXML_STRING *out)</span></span>
2.TiXmlAttribute
描述: 属性
公有函数:
<span style="font-family:SimSun;font-size:14px;"><span style="font-family:Microsoft YaHei;font-size:14px;">TiXmlAttribute()
TiXmlAttribute(const std::string& _name, const std::string& _value)
TiXmlAttribute(const char * _name, const char * _value)
const char * Name() const
const char * Value() const
const std:string& ValueStr() const
int IntValue() const
double DoubleValue() const
int QueryIntValue(int *_value) const
int QueryDoubleValue(double *_value) const
void SetName(const char* _name)
void SetValue(const char* _value)
void SetIntValue(int _value)
void SetDoubleValue(double _ value)
void SetName(const std::string & _name)
void SetValue(const std::string & _value)
const TiXmlAttribute * Next() const
const TiXmlAttribute * Previous() const
virtual void Print(FILE *cfile, int depth) const</span></span>
3. TiXmlNode
描述: 在文档对象模型(DOM)中,它是所有一切节点的父类
公有函数:
<span style="font-family:SimSun;font-size:14px;"><span style="font-family:Microsoft YaHei;font-size:14px;">const char * Value () const
const std::string & ValueStr () const
void SetValue (const char *_value)
void SetValue (const std::string &_value)
void Clear ()
TiXmlNode * Parent () FirstChild () const FirstChild (const char *value) const
const TiXmlNode *
const TiXmlNode *
TiXmlNode * FirstChild (const char *_value)
TiXmlNode * LastChild ()
TiXmlNode * LastChild (const char *_value)
const TiXmlNode * FirstChild (conststd::string &_value) const
TiXmlNode * FirstChild (const std::string&_value)
const TiXmlNode * LastChild (const std::string &_value) const
TiXmlNode * LastChild (const std::string&_value)
const TiXmlNode *
const TiXmlNode * IterateChildren (const TiXmlNode *previous) constIterateChildren (const char *value, const TiXmlNode *previous) const
const TiXmlNode * IterateChildren (const std::string &_value, constTiXmlNode *previous) const
TiXmlNode * IterateChildren (const std::string &_value, const TiXmlNode*previous)
TiXmlNode * InsertEndChild (const TiXmlNode &addThis)
TiXmlNode * LinkEndChild (TiXmlNode *addThis)
TiXmlNode * InsertBeforeChild (TiXmlNode *beforeThis, const TiXmlNode&addThis)
TiXmlNode * InsertAfterChild (TiXmlNode *afterThis, constTiXmlNode &addThis)
TiXmlNode * ReplaceChild (TiXmlNode*replaceThis, const TiXmlNode &withThis)
bool RemoveChild (TiXmlNode*removeThis)
const TiXmlNode *
const TiXmlNode *
const TiXmlNode * PreviousSibling () constPreviousSibling (const char *) const PreviousSibling (const std::string&_value) const
TiXmlNode * PreviousSibling (const std::string &_value)
const TiXmlNode * NextSibling (const std::string &_value) const
TiXmlNode * NextSibling (const std::string&_value)
const TiXmlNode * NextSibling () const
const TiXmlNode * NextSibling (const char *) const
const TiXmlElement * NextSiblingElement ()const
const TiXmlElement * NextSiblingElement (const char *) const
const TiXmlElement * NextSiblingElement(const std::string &_value) const
TiXmlElement * NextSiblingElement (const std::string &_value)
const TiXmlElement * FirstChildElement () const
const TiXmlElement * FirstChildElement (const char *_value) const
const TiXmlElement * FirstChildElement(const std::string &_value) const
TiXmlElement * FirstChildElement (const std::string &_value)
int Type () const
const TiXmlDocument * GetDocument () const
bool NoChildren () const
virtual const TiXmlDocument *
virtual const TiXmlElement *
virtual const TiXmlComment * ToDocument ()const ToElement () const ToComment () const
virtual const TiXmlUnknown * ToUnknown () const
virtual const TiXmlText * ToText () const
virtual const TiXmlDeclaration * ToDeclaration () const
virtual TiXmlDocument * ToDocument ()
virtual TiXmlElement * ToElement ()
virtual TiXmlComment * ToComment ()
virtual TiXmlUnknown * ToUnknown ()
virtual TiXmlText * ToText ()ToDeclaration ()
virtual TiXmlDeclaration *
virtual TiXmlNode * Clone () const =0
virtual bool Accept (TiXmlVisitor *visitor) const =0</span></span>
4.TiXmlComment
描述: 表示 XML 文件中的注释
公有函数
<span style="font-family:SimSun;font-size:14px;"><span style="font-family:Microsoft YaHei;font-size:14px;">TiXmlComment ()
TiXmlComment (const char *_value)
virtual TiXmlNode * Clone () const
virtual void Print (FILE *cfile, int depth) const
virtual const TiXmlComment * ToComment () const
virtual TiXmlComment * ToComment ()
virtual bool Accept (TiXmlVisitor *visitor)const</span></span>
5.TiXmlDeclaration
描述:表示 XML 文件中的声明
公有函数:
<span style="font-family:SimSun;font-size:14px;"><span style="font-family:Microsoft YaHei;font-size:14px;">TiXmlDeclaration ()
TiXmlDeclaration (const std::string &_version, const std::string&_encoding, const std::string &_standalone)
TiXmlDeclaration (const char *_version, const char *_encoding, const char*_standalone)
const char * Version () const
const char * Encoding () const
const char * Standalone () const Clone () const
virtual TiXmlNode *
virtual void Print (FILE *cfile, int depth)const
virtual const TiXmlDeclaration *
virtual TiXmlDeclaration * ToDeclaration () const ToDeclaration ()
virtual bool Accept (TiXmlVisitor*visitor) const</span></span>
6. TiXmlDocument
描述:在文档对象模型(DOM)中, 始终作为 XML 文档的最顶端节点
公有函数:
<span style="font-family:SimSun;font-size:14px;"><span style="font-family:Microsoft YaHei;font-size:14px;">TiXmlDocument ()
TiXmlDocument (const char *documentName)
TiXmlDocument (const std::string &documentName)
bool LoadFile (TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
bool SaveFile () const
bool LoadFile (const char *filename, TiXmlEncodingencoding=TIXML_DEFAULT_ENCODING)
bool SaveFile (const char *filename) const
bool LoadFile (FILE *, TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
bool SaveFile (FILE *) const
bool LoadFile (const std::string &filename, TiXmlEncodingencoding=TIXML_DEFAULT_ENCODING)
bool SaveFile (const std::string &filename) const
virtual const char * Parse (const char *p, TiXmlParsingData *data=0,TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
const TiXmlElement * RootElement() const
bool Error () const
const char * ErrorDesc () const
int ErrorId () const
int ErrorRow () const
int ErrorCol () const
void SetTabSize (int _tabsize)
void ClearError ()
void Print () const
virtual void Print (FILE *cfile, int depth=0) const
virtual const TiXmlDocument * ToDocument() const
virtual TiXmlDocument * ToDocument ()
virtual bool Accept (TiXmlVisitor*content) const
</span></span>
7. TiXmlElement
描述: TiXmlElement 是一个容器类,它有值和名称,也可以包含其它元素(如:文本,注释等),同时 它还可以拥有很多属性
公有函数:
<span style="font-family:SimSun;font-size:14px;"><span style="font-family:Microsoft YaHei;font-size:14px;">TiXmlElement (const char *in_value)
TiXmlElement (const std::string&_value)
const char * Attribute (const char *name) const
const char * Attribute (const char *name, int*i) const
const char * Attribute (const char *name,double *d) const
int QueryIntAttribute (const char *name,int *_value) const
int QueryDoubleAttribute (const char *name, double *_value) const
int QueryFloatAttribute (const char *name, float *_value) const
int QueryValueAttribute (const std::string &name, T *outValue) const
void SetAttribute (const char *name, constchar *_value)
void SetAttribute (const std::string &name, const std::string &_value)
void SetAttribute (const char *name, int value)
void SetDoubleAttribute (const char *name, double value)
void RemoveAttribute (const char *name)
void RemoveAttribute (const std::string &name)
const TiXmlAttribute * FirstAttribute () const
const TiXmlAttribute * LastAttribute ()const
const char * GetText () const
virtual TiXmlNode * Clone () const
virtual void Print (FILE *cfile, int depth) const
virtual const TiXmlElement * ToElement () const
virtual TiXmlElement * ToElement ()
virtual bool Accept (TiXmlVisitor *visitor) const
</span></span>
8.TiXmlText 描述: 表示 XML 文件中的文本节点
公有函数:
<span style="font-family:SimSun;font-size:14px;"><span style="font-family:Microsoft YaHei;font-size:14px;">TiXmlText (const char *initValue)
TiXmlText (const std::string&initValue)
virtual void Print (FILE *cfile, int depth) const
bool CDATA () const
void SetCDATA (bool _cdata)
virtual const TiXmlText * ToText () const
virtual TiXmlText * ToText ()
virtual bool Accept (TiXmlVisitor *content)const
</span></span>
9.TiXmlUnkown 描述:在 XML 文件中无法识别的节点用 TiXmlUnkown 来表示
公有函数:
<span style="font-family:SimSun;font-size:14px;"><span style="font-family:Microsoft YaHei;font-size:14px;">virtual TiXmlNode * Clone () const
virtual void Print (FILE *cfile, int depth) const
virtual const TiXmlUnknown * ToUnknown () const
virtual TiXmlUnknown * ToUnknown ()
virtual bool Accept (TiXmlVisitor *content) const</span></span>