I'm trying to print the XML document data in the console using the RapidXML Library in my C++ application.
I'm following the RapidXML Manual link here, but I got a compile-time error.
Here is my C++ code:
#include <iostream>
#include "rapidxml.hpp"
#include "rapidxml_utils.hpp"
#include "rapidxml_print.hpp"
int main() {
rapidxml::file<> xmlFile("beerJournal.xml");
rapidxml::xml_document<> doc;
doc.parse<0>(xmlFile.data());
std::cout << doc;
return 0;
}
Here is the error:
rapidxml_print.hpp:115: error: ‘print_children’ was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
out = print_children(out, node, flags, indent);
~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
rapidxml_print.hpp:169: ‘template<class OutIt, class Ch> OutIt rapidxml::internal::print_children(OutIt, const rapidxml::xml_node<Ch>*, int, int)’ declared here, later in the translation unit
inline OutIt print_children(OutIt out, const xml_node<Ch> *node, int flags, int indent)
^~~~~~~~~~~~~~
Obs.: I already tried the other two RapidXML print methods described in the manual (link above).
My setup:
I've come across the same issue in the past. The workaround presented in this SO answer has been working great for all of my GCC builds ever since.
To summarize the information of the other answer: It boils down to a name look up change made in GCC 4.7. The workaround consists of creating a file named rapidxml_ext.hpp
with the content below. Then include rapidxml_ext.hpp
in your client application/library.
rapidxml_ext.hpp
#pragma once
#include "rapidxml.hpp"
// Adding declarations to make it compatible with gcc 4.7 and greater
// See https://stackoverflow.com/a/55408678
namespace rapidxml {
namespace internal {
template <class OutIt, class Ch>
inline OutIt print_children(OutIt out, const xml_node<Ch>* node, int flags, int indent);
template <class OutIt, class Ch>
inline OutIt print_attributes(OutIt out, const xml_node<Ch>* node, int flags);
template <class OutIt, class Ch>
inline OutIt print_data_node(OutIt out, const xml_node<Ch>* node, int flags, int indent);
template <class OutIt, class Ch>
inline OutIt print_cdata_node(OutIt out, const xml_node<Ch>* node, int flags, int indent);
template <class OutIt, class Ch>
inline OutIt print_element_node(OutIt out, const xml_node<Ch>* node, int flags, int indent);
template <class OutIt, class Ch>
inline OutIt print_declaration_node(OutIt out, const xml_node<Ch>* node, int flags, int indent);
template <class OutIt, class Ch>
inline OutIt print_comment_node(OutIt out, const xml_node<Ch>* node, int flags, int indent);
template <class OutIt, class Ch>
inline OutIt print_doctype_node(OutIt out, const xml_node<Ch>* node, int flags, int indent);
template <class OutIt, class Ch>
inline OutIt print_pi_node(OutIt out, const xml_node<Ch>* node, int flags, int indent);
}
}
#include "rapidxml_print.hpp"