C + + generation of XML

Source: Internet
Author: User

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

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.