TinyXML The latest release is 2.5.3, always want to use, today took out a little time with the use, now the master of the preliminary simple usage to tidy up. First compile the library file, TinyXML has two compiled versions, depending on whether you use STL. After build, in the new program code include the tinyxml.h in the library. Here's My Code: #include<cstdio>
#include<iostream>
#include".. /tinyxml.h "
intMain ()
{
Tixmldocument MyDoc ("Testtinyxml.xml");Mydoc.insertendchild (Tixmldeclaration ("1.0", "gb2312", "yes"));
Mydoc.insertendchild (Tixmlelement ("RootNode"));
tixmlelement* RootNode = Mydoc.rootelement ();
tixmlelement* Subelem = Rootnode->insertendchild (tixmlelement ("Subnode:size"))->toelement ();
Subelem->setattribute ("value", 16);
Subelem->insertendchild (Tixmltext ("Text size"));Mydoc.savefile ();
Mydoc.clear ();Mydoc.loadfile ("Testtinyxml.xml");
Tixmlhandle Dochandle (&mydoc);
tixmldeclaration* Pdec = Mydoc.firstchild ()->todeclaration ();
if(PDEC)
Std::cout << "Version:" << pdec->version () << "\nencoding:" << pdec->encoding () << " \nstandalong: "<< pdec->standalone () <<" \ n ";Subelem = Dochandle.firstchildelement (). Element ();
Char* pch = (Char*) Subelem->gettext ();
if(!PCH)
{
Subelem = Subelem->firstchild ()->toelement ();
if(Subelem)
{
PCH = (Char*) Subelem->gettext ();
if(PCH)
Std::cout << pch << "is";
Std::cout << Subelem->attribute ("value") << "\ n";
}//If
}//Ifreturn0;
}The program runs output as follows: version:1.0
encoding:gb2312
Standalong:yes
Text size is 16
After execution, a testtinyxml.xml file is generated with the following contents:<?xmlversion="1.0"encoding="GB2312"standalone="Yes"?>
<RootNode>
<subnode:sizevalue=" -">Text size</SubNode:Size>
</rootnode> This little gadget does not look small, but it can be said to be short, enough for my current use. Let's get this sorted out today and have time to write.
Simple usage of TinyXML