Mercurial > minori
annotate dep/pugixml/docs/samples/modify_remove.cpp @ 353:2f094656e775
sys/x11/settings: misc fixups
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Sun, 14 Jul 2024 23:27:43 -0400 |
parents | d10b6c6b432e |
children |
rev | line source |
---|---|
55
d10b6c6b432e
add xml lib, we will need to use it eventually
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
1 #include "pugixml.hpp" |
d10b6c6b432e
add xml lib, we will need to use it eventually
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
2 |
d10b6c6b432e
add xml lib, we will need to use it eventually
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
3 #include <iostream> |
d10b6c6b432e
add xml lib, we will need to use it eventually
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
4 |
d10b6c6b432e
add xml lib, we will need to use it eventually
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
5 int main() |
d10b6c6b432e
add xml lib, we will need to use it eventually
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
6 { |
d10b6c6b432e
add xml lib, we will need to use it eventually
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
7 pugi::xml_document doc; |
d10b6c6b432e
add xml lib, we will need to use it eventually
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
8 if (!doc.load_string("<node><description>Simple node</description><param name='id' value='123'/></node>")) return -1; |
d10b6c6b432e
add xml lib, we will need to use it eventually
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
9 |
d10b6c6b432e
add xml lib, we will need to use it eventually
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
10 // tag::code[] |
d10b6c6b432e
add xml lib, we will need to use it eventually
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
11 // remove description node with the whole subtree |
d10b6c6b432e
add xml lib, we will need to use it eventually
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
12 pugi::xml_node node = doc.child("node"); |
d10b6c6b432e
add xml lib, we will need to use it eventually
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
13 node.remove_child("description"); |
d10b6c6b432e
add xml lib, we will need to use it eventually
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
14 |
d10b6c6b432e
add xml lib, we will need to use it eventually
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
15 // remove id attribute |
d10b6c6b432e
add xml lib, we will need to use it eventually
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
16 pugi::xml_node param = node.child("param"); |
d10b6c6b432e
add xml lib, we will need to use it eventually
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
17 param.remove_attribute("value"); |
d10b6c6b432e
add xml lib, we will need to use it eventually
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
18 |
d10b6c6b432e
add xml lib, we will need to use it eventually
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
19 // we can also remove nodes/attributes by handles |
d10b6c6b432e
add xml lib, we will need to use it eventually
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
20 pugi::xml_attribute id = param.attribute("name"); |
d10b6c6b432e
add xml lib, we will need to use it eventually
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
21 param.remove_attribute(id); |
d10b6c6b432e
add xml lib, we will need to use it eventually
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
22 // end::code[] |
d10b6c6b432e
add xml lib, we will need to use it eventually
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
23 |
d10b6c6b432e
add xml lib, we will need to use it eventually
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
24 doc.print(std::cout); |
d10b6c6b432e
add xml lib, we will need to use it eventually
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
25 } |
d10b6c6b432e
add xml lib, we will need to use it eventually
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
26 |
d10b6c6b432e
add xml lib, we will need to use it eventually
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
27 // vim:et |