I have been having some trouble using RapidXML to parse a string. I receive an error from within Eclipse claiming the parse function does not exist.
make all
Building file: ../search.cpp
Invoking: Cross G++ Compiler
g++ -DDEBUG -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"search.d" -MT"search.d" -o "search.o" "../search.cpp"
../search.cpp: In function ‘void search(CURL*, CURLcode, std::string, std::string)’:
../search.cpp:29:27: error: no matching function for call to ‘rapidxml::xml_document<>::parse(const char*)’
../search.cpp:29:27: note: candidate is:
../rapidxml-1.13/rapidxml.hpp:1381:14: note: template<int Flags> void rapidxml::xml_document::parse(Ch*) [with int Flags = Flags, Ch = char]
make: *** [search.o] Error 1
The following code raises an error:
rapidxml::xml_document<> doc; // This has no errors
doc.parse<0>(data.c_str()); // This line raises the error (data is a string)
For reference here is the online documentation: http://rapidxml.sourceforge.net/manual.html#namespacerapidxml_1parsing
RapidXML comes as four header files:
- rapidxml_iterators.hpp
- rapidxml_print.hpp <--contains errors, but build is successful with them
- rapidxml_utils.hpp <--contains errors, but build is successful with them
- rapidxml.hpp <--linked by program, contains parse function
How do I resolve the error in my code, and do I first need so resolve compiler errors in the headers somehow?
The problem is that the
char*
returned from callingc_str()
on astd::string
is actually aconst char*
which is no good for the parse function (parsing actually changes the string that it parses in rapidXML). This means we need to copy the string before we parse itI have not attempted to compile the above so there maybe errors, the point is that
c_str()
returns aconst char*
andparse()
must take a non-constchar*
. Hope this helps. As for your headers, I usually get away with only usingincluded in my source files. You have no linker issues because RapidXML is header only implementation (which makes it nice in my opinion).