docs: Converted some samples to Unix newline

This commit is contained in:
Arseny Kapoulkine 2015-03-22 01:01:46 -07:00
parent 56bdc6c5ea
commit 40fa405751
3 changed files with 100 additions and 100 deletions

View File

@ -1,27 +1,27 @@
#include "pugixml.hpp" #include "pugixml.hpp"
#include <iostream> #include <iostream>
int main() int main()
{ {
// tag::code[] // tag::code[]
// get a test document // get a test document
pugi::xml_document doc; pugi::xml_document doc;
doc.load_string("<foo bar='baz'><call>hey</call></foo>"); doc.load_string("<foo bar='baz'><call>hey</call></foo>");
// add a custom declaration node // add a custom declaration node
pugi::xml_node decl = doc.prepend_child(pugi::node_declaration); pugi::xml_node decl = doc.prepend_child(pugi::node_declaration);
decl.append_attribute("version") = "1.0"; decl.append_attribute("version") = "1.0";
decl.append_attribute("encoding") = "UTF-8"; decl.append_attribute("encoding") = "UTF-8";
decl.append_attribute("standalone") = "no"; decl.append_attribute("standalone") = "no";
// <?xml version="1.0" encoding="UTF-8" standalone="no"?> // <?xml version="1.0" encoding="UTF-8" standalone="no"?>
// <foo bar="baz"> // <foo bar="baz">
// <call>hey</call> // <call>hey</call>
// </foo> // </foo>
doc.save(std::cout); doc.save(std::cout);
std::cout << std::endl; std::cout << std::endl;
// end::code[] // end::code[]
} }
// vim:et // vim:et

View File

@ -1,35 +1,35 @@
#include "pugixml.hpp" #include "pugixml.hpp"
#include <iostream> #include <iostream>
int main() int main()
{ {
pugi::xml_document doc; pugi::xml_document doc;
// get a test document // get a test document
doc.load_string("<project><name>test</name><version>1.1</version><public>yes</public></project>"); doc.load_string("<project><name>test</name><version>1.1</version><public>yes</public></project>");
pugi::xml_node project = doc.child("project"); pugi::xml_node project = doc.child("project");
// tag::access[] // tag::access[]
std::cout << "Project name: " << project.child("name").text().get() << std::endl; std::cout << "Project name: " << project.child("name").text().get() << std::endl;
std::cout << "Project version: " << project.child("version").text().as_double() << std::endl; std::cout << "Project version: " << project.child("version").text().as_double() << std::endl;
std::cout << "Project visibility: " << (project.child("public").text().as_bool(/* def= */ true) ? "public" : "private") << std::endl; std::cout << "Project visibility: " << (project.child("public").text().as_bool(/* def= */ true) ? "public" : "private") << std::endl;
std::cout << "Project description: " << project.child("description").text().get() << std::endl; std::cout << "Project description: " << project.child("description").text().get() << std::endl;
// end::access[] // end::access[]
std::cout << std::endl; std::cout << std::endl;
// tag::modify[] // tag::modify[]
// change project version // change project version
project.child("version").text() = 1.2; project.child("version").text() = 1.2;
// add description element and set the contents // add description element and set the contents
// note that we do not have to explicitly add the node_pcdata child // note that we do not have to explicitly add the node_pcdata child
project.append_child("description").text().set("a test project"); project.append_child("description").text().set("a test project");
// end::modify[] // end::modify[]
doc.save(std::cout); doc.save(std::cout);
} }
// vim:et // vim:et

View File

@ -1,38 +1,38 @@
#include "pugixml.hpp" #include "pugixml.hpp"
#include <iostream> #include <iostream>
#include <string> #include <string>
int main() int main()
{ {
pugi::xml_document doc; pugi::xml_document doc;
if (!doc.load_file("xgconsole.xml")) return -1; if (!doc.load_file("xgconsole.xml")) return -1;
// tag::code[] // tag::code[]
// Select nodes via compiled query // Select nodes via compiled query
pugi::xpath_variable_set vars; pugi::xpath_variable_set vars;
vars.add("remote", pugi::xpath_type_boolean); vars.add("remote", pugi::xpath_type_boolean);
pugi::xpath_query query_remote_tools("/Profile/Tools/Tool[@AllowRemote = string($remote)]", &vars); pugi::xpath_query query_remote_tools("/Profile/Tools/Tool[@AllowRemote = string($remote)]", &vars);
vars.set("remote", true); vars.set("remote", true);
pugi::xpath_node_set tools_remote = query_remote_tools.evaluate_node_set(doc); pugi::xpath_node_set tools_remote = query_remote_tools.evaluate_node_set(doc);
vars.set("remote", false); vars.set("remote", false);
pugi::xpath_node_set tools_local = query_remote_tools.evaluate_node_set(doc); pugi::xpath_node_set tools_local = query_remote_tools.evaluate_node_set(doc);
std::cout << "Remote tool: "; std::cout << "Remote tool: ";
tools_remote[2].node().print(std::cout); tools_remote[2].node().print(std::cout);
std::cout << "Local tool: "; std::cout << "Local tool: ";
tools_local[0].node().print(std::cout); tools_local[0].node().print(std::cout);
// You can pass the context directly to select_nodes/select_node // You can pass the context directly to select_nodes/select_node
pugi::xpath_node_set tools_local_imm = doc.select_nodes("/Profile/Tools/Tool[@AllowRemote = string($remote)]", &vars); pugi::xpath_node_set tools_local_imm = doc.select_nodes("/Profile/Tools/Tool[@AllowRemote = string($remote)]", &vars);
std::cout << "Local tool imm: "; std::cout << "Local tool imm: ";
tools_local_imm[0].node().print(std::cout); tools_local_imm[0].node().print(std::cout);
// end::code[] // end::code[]
} }
// vim:et // vim:et