Use boost: property_tree to generate xml with attribute

Source: Internet
Author: User

I have previously written an article "using boost property tree to parse XML with attribute", but my sister-in-law has never posted this article. It's almost three years since I posted the previous article. It's so fast.
This is the next article. Use boost: property_tree to generate xml with attribute.

View the Demo code directly:

# Include <iostream> # include <sstream> # include <boost/property_tree/xml_parser.hpp> using namespace STD; int main () {using boost: property_tree: ptree; ptree pt; ptree tab1; ptree tab2; tab1.put ("attr1", "value1"); tab1.put ("attr1. <xmlattr>. code "," ABC "); tab1.put (" attr2 "," value2 "); tab2.put (" attr3 "," value3 "); tab2.put (" attr3. <xmlattr>. code "," XYZ "); ptree array; Auto & A = array. add_child ("Table1", tab1);. put ("<xmlattr>. tabid "," 1 "); Auto & B = array. add_child ("Table2", tab2); B. put ("<xmlattr>. tabid "," 2 "); PT. put_child ("demoxml", array); ostringstream OSS; write_xml (OSs, PT, xml_writer_settings <char> ('', 2); cout <OSS. STR () <Endl; return 0 ;}

The generated XML is as follows:

<? XML version = "1.0" encoding = "UTF-8"?> <Demoxml> <Table1 Tabid = "1"> <attr1 code = "ABC"> value1 </attr1> <attr2> value2 </attr2> </Table1> <Table2 Tabid = ""2"> <attr3 code = "XYZ"> value3 </attr3> </Table2> </demoxml>

!!!!!!! Welcome to reprint, please indicate the link of this article: http://blog.csdn.net/mosaic/article/details/39047327 !!!!!

Use boost: property_tree to generate xml with attribute

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.