summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/pugixml/docs/samples/modify_base.cpp
diff options
context:
space:
mode:
author Miodrag Milanovic <mmicko@gmail.com>2016-06-25 19:01:45 +0200
committer Miodrag Milanovic <mmicko@gmail.com>2016-06-25 19:54:44 +0200
commit8042037fd9e6d012f04f8dcc13c2215d72ccee06 (patch)
tree3babbd12b19f6b0cd8515da6f5f3d502369ec4ae /3rdparty/pugixml/docs/samples/modify_base.cpp
parent3739530a86b94869daecea75f8a0938a14e5741a (diff)
Added PugiXML and used it for hashfile (nw)
Diffstat (limited to '3rdparty/pugixml/docs/samples/modify_base.cpp')
-rw-r--r--3rdparty/pugixml/docs/samples/modify_base.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/3rdparty/pugixml/docs/samples/modify_base.cpp b/3rdparty/pugixml/docs/samples/modify_base.cpp
new file mode 100644
index 00000000000..7c4819b329d
--- /dev/null
+++ b/3rdparty/pugixml/docs/samples/modify_base.cpp
@@ -0,0 +1,43 @@
+#include "pugixml.hpp"
+
+#include <string.h>
+#include <iostream>
+
+int main()
+{
+ pugi::xml_document doc;
+ if (!doc.load_string("<node id='123'>text</node><!-- comment -->", pugi::parse_default | pugi::parse_comments)) return -1;
+
+ // tag::node[]
+ pugi::xml_node node = doc.child("node");
+
+ // change node name
+ std::cout << node.set_name("notnode");
+ std::cout << ", new node name: " << node.name() << std::endl;
+
+ // change comment text
+ std::cout << doc.last_child().set_value("useless comment");
+ std::cout << ", new comment text: " << doc.last_child().value() << std::endl;
+
+ // we can't change value of the element or name of the comment
+ std::cout << node.set_value("1") << ", " << doc.last_child().set_name("2") << std::endl;
+ // end::node[]
+
+ // tag::attr[]
+ pugi::xml_attribute attr = node.attribute("id");
+
+ // change attribute name/value
+ std::cout << attr.set_name("key") << ", " << attr.set_value("345");
+ std::cout << ", new attribute: " << attr.name() << "=" << attr.value() << std::endl;
+
+ // we can use numbers or booleans
+ attr.set_value(1.234);
+ std::cout << "new attribute value: " << attr.value() << std::endl;
+
+ // we can also use assignment operators for more concise code
+ attr = true;
+ std::cout << "final attribute value: " << attr.value() << std::endl;
+ // end::attr[]
+}
+
+// vim:et