1#include <stdio.h>2#include <string>3 using namespacestd;4 //1. Download TinyXML and add header file5 //2. Hooking up child nodes by parent node Linkendchild6#include".. /tinyxml/tinyxml.h" //header file Path7 8 inttest1 ()9 {Ten tixmldocument Xml_doc; One A //add an XML declaration -Xml_doc. Linkendchild (NewTixmldeclaration ("1.0","GBK","" )); - the //Add a root element -Tixmlelement * Xml_root =NewTixmlelement ("Root"); - Xml_doc. Linkendchild (xml_root); - + //add additional child elements under the root element - if(1) + { A //Add Host attixmlelement* Xml_child =NewTixmlelement ("Host"); -Xml_root->Linkendchild (xml_child); - //Add document Content -Xml_child->linkendchild (NewTixmltext ("afanihao.cn")); - - //Setting Properties inXml_child->setattribute ("checked","true"); -Xml_child->setattribute (" Station",1001); to } + - if(1) the { * //nesting a nested element $tixmlelement* xml_client =NewTixmlelement ("Client"); Panax NotoginsengXml_root->Linkendchild (xml_client); - thetixmlelement* Xml_clientname =NewTixmlelement ("name"); +Xml_clientname->linkendchild (NewTixmltext ("Shaofa")); AXml_client->Linkendchild (xml_clientname); the +tixmlelement* Xml_clientid =NewTixmlelement ("ID"); -Xml_clientid->linkendchild (NewTixmltext ("200501")); $Xml_client->Linkendchild (xml_clientid); $ } - - the //1. Save to file -Xml_doc. SaveFile ("Example02a.xml");Wuyi the //2. Turn to string to save - stringtext; WuText <<Xml_doc; - return 0; About } $ - - intMain () - { A + test1 (); the return 0; -}
C + + generation of XML