Simple usage of TinyXML

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.