source: icGREP/icgrep-devel/icgrep/combine/pugixml/docs/samples/modify_base.cpp @ 5516

Last change on this file since 5516 was 5516, checked in by faldebey, 22 months ago

added combinatorial testing tool

File size: 1.3 KB
RevLine 
[5516]1#include "pugixml.hpp"
2
3#include <string.h>
4#include <iostream>
5
6int main()
7{
8    pugi::xml_document doc;
9    if (!doc.load_string("<node id='123'>text</node><!-- comment -->", pugi::parse_default | pugi::parse_comments)) return -1;
10
11    // tag::node[]
12    pugi::xml_node node = doc.child("node");
13
14    // change node name
15    std::cout << node.set_name("notnode");
16    std::cout << ", new node name: " << node.name() << std::endl;
17
18    // change comment text
19    std::cout << doc.last_child().set_value("useless comment");
20    std::cout << ", new comment text: " << doc.last_child().value() << std::endl;
21
22    // we can't change value of the element or name of the comment
23    std::cout << node.set_value("1") << ", " << doc.last_child().set_name("2") << std::endl;
24    // end::node[]
25
26    // tag::attr[]
27    pugi::xml_attribute attr = node.attribute("id");
28
29    // change attribute name/value
30    std::cout << attr.set_name("key") << ", " << attr.set_value("345");
31    std::cout << ", new attribute: " << attr.name() << "=" << attr.value() << std::endl;
32
33    // we can use numbers or booleans
34    attr.set_value(1.234);
35    std::cout << "new attribute value: " << attr.value() << std::endl;
36
37    // we can also use assignment operators for more concise code
38    attr = true;
39    std::cout << "final attribute value: " << attr.value() << std::endl;
40    // end::attr[]
41}
42
43// vim:et
Note: See TracBrowser for help on using the repository browser.