Read-write function of "C + +" "TinyXml" XML file--writing XML file

Source: Internet
Author: User

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

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.