Percent symbol replaced with the word "Success" in cdata
                
                Brought to you by:
                
                    kaalus
                    
                
            
            
        
        
        
    My code looks like this:
std::string str = "% mem=2000MB"; // This stays in scope until after the document is written
xml_node<>* text = doc.allocate_node(node_cdata, NULL, str.c_str(), 0, str.length());
...
This text is being written in the cdata tag:
Here's a complete sample program:
#include <stdio.h> #include <string> #include "rapidxml/rapidxml.hpp" #include "rapidxml/rapidxml_utils.hpp" #include "rapidxml/rapidxml_print.hpp" int main(int argc, char* argv[]) { using namespace rapidxml; const char* fileName = "test.xml"; printf("Writing file: %s\n", fileName); xml_document<> doc; xml_node<>* test = doc.allocate_node(node_element, "test"); doc.append_node(test); std::string str = "% mem=2000MB"; xml_node<>* text = doc.allocate_node(node_cdata, NULL, str.c_str(), 0, str.length()); test->append_node(text); FILE *f = fopen(fileName, "w"); if (f == NULL) { printf("Error writing file: %s\n", fileName); return false; } std::string s; print(std::back_inserter(s), doc, 0); fprintf(f, s.c_str()); fclose(f); return 0; }The output is:
<test>
<![CDATA[Successem=2000MB]]>
</test>
Perhaps you should NOT use "fprintf" if you simply want to print the content of a string - a common programming error (just because we use this (f)printf so often) and also a source of exploits :)
Use fputs instead or "fprintf(f,"%s",s.c_str());".
Should have caught that myself. Thanks!