TinyXML tools are common and simple tools for XML reading and writing in C + +
Need to load
#include "tinyxml\tinyxml.h"
In TinyXML, some classes are defined according to the various elements of XML:
Tixmlbase: The base class for the entire TinyXML model.
Tixmlattribute: A property that corresponds to an element in XML.
Tixmlnode: Corresponds to a node in the DOM structure.
Tixmlcomment: corresponding to comments in XML
Tixmldeclaration: Corresponds to the declaration part of XML, namely < Versiong= "1.0"?>.
Tixmldocument: The entire document that corresponds to XML.
Tixmlelement: The element that corresponds to the XML.
Tixmltext: The text portion corresponding to the XML
Tixmlunknown: Corresponds to an unknown part of XML.
Tixmlhandler: Defines some operations for XML.
Write the XML file method:
Document class Tixmldocument
Tixmldocument doc;string Outputfilepath = "E:\\text.xml"; Tixmlelement *converterelement = new Tixmlelement ("Converter");d OC. Linkendchild (converterelement);d oc. SaveFile (Outputfilepath.c_str ());
ELEMENT Node class Tixmlelement
Add Node method Linkendchild (tixmlnode* node)
Set Node Property method setattribute (const char * CNAME, const char * cvalue)
Tixmldocument doc;string Outputfilepath = "E:\\text.xml"; Tixmlelement *converterelement = new Tixmlelement ("Converter");d OC. Linkendchild (converterelement); Tixmlelement *configureelement = new Tixmlelement ("Configure"); Converterelement->linkendchild (configureelement) ; Tixmlelement *generalelement = new Tixmlelement ("Options"); Configureelement->linkendchild (generalelement); Generalelement->setattribute ("Name", "General");
Doc. SaveFile (Outputfilepath.c_str ());
The effect is as follows
<Converter> <Configure> <options name= "General" > </configure></converter >
Content class Tixmltext
Tixmlelement *optionelement = new Tixmlelement ("Option"); Optionelement->setattribute ("Name", "Value"); Tixmltext *namecontent = new Tixmltext ("text"); Optionelement->linkendchild (namecontent); return optionelement;
The effect is as follows
<option name= "Value" >text</Option>
Read-write function of "C + +" "TinyXml" XML file--writing XML file