Question

I have multiple documents to parse and I need access to all the document objects for the lifetime of the creating class. How do I create an array of xml_document pointers as a member variable?

I've tried creating a single member variable as follows:

private: rapidxml::xml_document<> *m_pDoc; // doesn't compile

error: name followed by "::" must be a class or namespace name

I'm sure this is because the template class isn't well defined but I'm not sure how to properly define the pointer.

Was it helpful?

Solution

That compiles fine for me. The error message implies you've forgotten this, maybe?

#include "rapidxml.hpp"

OTHER TIPS

Rapidxml references to the pointers of your vector buffer every time you pass an xml. So store both your buffers and also the xml_document<> docs.

Put the filepaths of your xml docs

char *XMLFilePaths[numXmlDocs] = {"../PersonDatasetA/xmlFile.xml","../PersonDatasetB/xmlFile.xml"};

Store both the buffers and also the xml documents into arrays

std::array<vector<char>,numXmlDocs> XMLDocBuffers;
std::array<xml_document<>,numXmlDocs> XMLDocs;

//For each xml doc, read and store it in an array
for(int i=0;i<numXmlDocs;i++){      
    //Parse each xml into the buffer array
    char xmlFileName[100] ;
    sprintf(xmlFileName,"%s",XMLFilePaths[i]);
    ifstream theFile (xmlFileName);
    vector<char> buffer((istreambuf_iterator<char>(theFile)), istreambuf_iterator<char>());
    buffer.push_back('\0'); 

    //Store the buffer
    XMLDocBuffers[i] =  buffer; 

    // Parse the buffer usingthe xml file parsing library into doc 
    XMLDocs[i].parse<0>(&(XMLDataset_StringDocs[i][0]));

    xml_node<> *root_node;      // Find the root node
    root_node = (XMLDocs[i]).first_node(typesOfSamples);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top