0

I have a class with a rapidxml::xml_document, but when I try to parse XML into it, it populates with... well, not garbage, but information about my namespaces and the like.

In the code below I have examples of what I've tried, commented out, and a local variable, doc being properly populated from the class member string.

Any ideas?

.h

class PrintHeadGeometry
{
    // XML Stuff
    static rapidxml::xml_document<> m_xmlDocDPHX;   
    static std::string m_xmlStringDPHX;  

    // etc
};

.cpp

// near the top
rapidxml::xml_document<> PrintHeadGeometry::m_xmlDocDPHX;
std::string PrintHeadGeometry::m_xmlStringDPHX = "";

// in my "load" function
std::ifstream file(filename);
std::stringstream buffer;
buffer << file.rdbuf();
file.close();
std::string content(buffer.str());
m_xmlStringDPHX = content;

// NEITHER OF THESE WORK - I WANTED THE TOP ONE, IDEALLY
//
//m_xmlDocDPHX.parse<0>(&m_xmlStringDPHX[0]);
//m_xmlDocDPHX.parse<0>(&content[0]);

// THIS WORKS THOUGH
//
rapidxml::xml_document<> doc;
doc.parse<0>(&m_xmlStringDPHX[0]);
technorabble
  • 391
  • 7
  • 16
  • Without an SSSCE I can't help much, but a typical RapidXML problem is not realizing that RapidXML just creates pointers into the string that you pass to `parse()`, so if that string changes/goes out of scope/gets freed/used then all the pointers in the RapidXml `xml_document` will point at garbage. – Roddy Jan 11 '14 at 20:04
  • Thanks Roddy. I don't think that is the problem here, as I'm checking the contents of the doc immediately after parsing for now. And I'm sorry, I don't know what an SSSCE is...? – technorabble Jan 13 '14 at 08:54
  • My bad. I always get that acronym wrong : http://sscce.org/ (basically, a small, *complete* example of the problem) – Roddy Jan 20 '14 at 23:09

0 Answers0