Mercurial > minori
comparison dep/pugixml/docs/samples/text.cpp @ 55:d10b6c6b432e
add xml lib, we will need to use it eventually
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Tue, 26 Sep 2023 12:37:08 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
54:466ac9870df9 | 55:d10b6c6b432e |
---|---|
1 #include "pugixml.hpp" | |
2 | |
3 #include <iostream> | |
4 | |
5 int main() | |
6 { | |
7 pugi::xml_document doc; | |
8 | |
9 // get a test document | |
10 doc.load_string("<project><name>test</name><version>1.1</version><public>yes</public></project>"); | |
11 | |
12 pugi::xml_node project = doc.child("project"); | |
13 | |
14 // tag::access[] | |
15 std::cout << "Project name: " << project.child("name").text().get() << std::endl; | |
16 std::cout << "Project version: " << project.child("version").text().as_double() << std::endl; | |
17 std::cout << "Project visibility: " << (project.child("public").text().as_bool(/* def= */ true) ? "public" : "private") << std::endl; | |
18 std::cout << "Project description: " << project.child("description").text().get() << std::endl; | |
19 // end::access[] | |
20 | |
21 std::cout << std::endl; | |
22 | |
23 // tag::modify[] | |
24 // change project version | |
25 project.child("version").text() = 1.2; | |
26 | |
27 // add description element and set the contents | |
28 // note that we do not have to explicitly add the node_pcdata child | |
29 project.append_child("description").text().set("a test project"); | |
30 // end::modify[] | |
31 | |
32 doc.save(std::cout); | |
33 } | |
34 | |
35 // vim:et |