Rapidxml usage and examples in C + + (source code)

Source: Internet
Author: User

Rapidxml is a fast XML library that is 50-100 times faster than TinyXML.     This article gives the source code for creating, reading, and writing XML. Since Sina Blog does not support text file upload, in the use of the following code need to download Rapidxml, about this library is: official website:https://sourceforge.net/projects/rapidxml/, the source of this library only four files are: about Raidxml information related to the introduction of the Internet has a lot of information, here I do not repeat the introduction, the following direct code:
#include"stdafx.h"#include"stdlib.h"#include<iostream>//The following three files are the library files required for this section of the Code#include"rapidxml/rapidxml.hpp"#include"rapidxml/rapidxml_utils.hpp"#include"rapidxml/rapidxml_print.hpp"intcreatexml ();intreadandchangexml ();int_tmain (intARGC, _tchar*argv[]) {    //Test CasesCreatexml (); //Test CasesReadandchangexml (); System ("Pause"); return 0;}//Create a name called Config2.xml fileintCreatexml () {rapidxml::xml_document<>Doc; Rapidxml::xml_node<>* rot = Doc.allocate_node (rapidxml::node_pi,doc.allocate_string ("XML version= ' 1.0 ' encoding= ' utf-8 '"));    Doc.append_node (ROT); Rapidxml::xml_node<>* node = Doc.allocate_node (Rapidxml::node_element,"Config","Information");    Doc.append_node (node); Rapidxml::xml_node<>* color = Doc.allocate_node (Rapidxml::node_element,"Color", NULL); Node-Append_node (color); Color->append_node (Doc.allocate_node (Rapidxml::node_element,"Red","0.1")); Color->append_node (Doc.allocate_node (Rapidxml::node_element,"Green","0.1")); Color->append_node (Doc.allocate_node (Rapidxml::node_element,"Blue","0.1")); Color->append_node (Doc.allocate_node (Rapidxml::node_element,"Alpha","1.0")); Rapidxml::xml_node<>* size = Doc.allocate_node (Rapidxml::node_element,"size", NULL); Size->append_node (Doc.allocate_node (Rapidxml::node_element,"x","640")); Size->append_node (Doc.allocate_node (Rapidxml::node_element,"y","480")); Node-Append_node (size); Rapidxml::xml_node<>* mode = Doc.allocate_node (Rapidxml::node_element,"Mode","Screen mode"); Mode->append_attribute (Doc.allocate_attribute ("fullscreen","false")); Node-append_node (mode); STD::stringtext; Rapidxml::p rint (Std::back_inserter (text), Doc,0); Std::cout<<text<<Std::endl; Std::ofstream out(".. /config/config1.xml");  out<<Doc; return 0;}//Read and modify Config3.xmlintReadandchangexml () {Rapidxml::file<> Fdoc (".. /config/config2.xml"); Std::cout<<fdoc.data () <<Std::endl; Rapidxml::xml_document<>Doc; Doc.parse<0>(Fdoc.data ()); Std::cout<<doc.name () <<Std::endl; //! Get root noderapidxml::xml_node<>* root =Doc.first_node (); Std::cout<<root->name () <<Std::endl; //get the first node of the root noderapidxml::xml_node<>* Node1 = root->First_node (); Std::cout<<node1->name () <<Std::endl; Rapidxml::xml_node<>* Node11 = node1->First_node (); Std::cout<<node11->name () <<Std::endl; Std::cout<<node11->value () <<Std::endl; //After you modify it, save it again.rapidxml::xml_node<>* size = Root->first_node ("size"); Size->append_node (Doc.allocate_node (Rapidxml::node_element,"W","1")); Size->append_node (Doc.allocate_node (Rapidxml::node_element,"h","1")); STD::stringtext; Rapidxml::p rint (Std::back_inserter (text), Doc,0); Std::cout<<text<<Std::endl; Std::ofstream out(".. /config/config2.xml");  out<<Doc; return 0;}

Rapidxml usage and examples in C + + (source code)

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.