I'm using RapidXml in a c++ program. Well ok no problem it works. I just do not understand why I must use pointers instead of variable values... If you take a look to the RapidXml wiki page, some examples are provided, this is the one provided by RapidXml developers:
#include <iostream>
#include <string>
#include "rapidxml-1.13/rapidxml.hpp"
#include "rapidxml-1.13/rapidxml_print.hpp"
int main(int argc, char** argv);
int main(int argc, char** argv) {
using namespace rapidxml;
xml_document<> doc;
// xml declaration
xml_node<>* decl = doc.allocate_node(node_declaration);
decl->append_attribute(doc.allocate_attribute("version", "1.0"));
decl->append_attribute(doc.allocate_attribute("encoding", "utf-8"));
doc.append_node(decl);
// root node
xml_node<>* root = doc.allocate_node(node_element, "rootnode");
root->append_attribute(doc.allocate_attribute("version", "1.0"));
root->append_attribute(doc.allocate_attribute("type", "example"));
doc.append_node(root);
// child node
xml_node<>* child = doc.allocate_node(node_element, "childnode");
root->append_node(child);
xml_node<>* child2 = doc.allocate_node(node_element, "childnode");
root->append_node(child2);
std::string xml_as_string;
// watch for name collisions here, print() is a very common function name!
print(std::back_inserter(xml_as_string), doc);
std::cout << xml_as_string << std::endl;
// xml_as_string now contains the XML in string form, indented
// (in all its angle bracket glory)
std::string xml_no_indent;
// print_no_indenting is the only flag that print() knows about
print(std::back_inserter(xml_no_indent), doc, print_no_indenting);
// xml_no_indent now contains non-indented XML
std::cout << xml_no_indent << std::endl;
}
Well, why does it use a pointer to xml_node???
I ask this because I need to a function to return a xml_node...
So if I do this:
xml_node<>* mynode = ... return *mynode;
is it ok?? Because I want to use the returned node and all its children later. Is it good to do in this way? If not, how should I do?