Mercurial > minori
comparison dep/pugixml/docs/samples/text.cpp @ 367:8d45d892be88 default tip
*: instead of pugixml, use Qt XML features
this means we have one extra Qt dependency though...
author | Paper <paper@tflc.us> |
---|---|
date | Sun, 17 Nov 2024 22:55:47 -0500 |
parents | 886f66775f31 |
children |
comparison
equal
deleted
inserted
replaced
366:886f66775f31 | 367:8d45d892be88 |
---|---|
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 |