-1

我有多个要解析的文档,并且我需要在创建类的生命周期内访问所有文档对象。如何创建一个 xml_document 指针数组作为成员变量?

我尝试创建一个成员变量,如下所示:

私人:rapidxml::xml_document<> *m_pDoc;// 不编译

错误:名称后跟“::”必须是类或命名空间名称

我确定这是因为模板类定义不明确,但我不确定如何正确定义指针。

4

2 回答 2

1

这对我来说很好。错误消息暗示您可能忘记了这一点?

#include "rapidxml.hpp"

于 2013-12-02T11:14:12.273 回答
0

每次传递 xml 时,Rapidxml 都会引用向量缓冲区的指针。所以存储你的缓冲区和 xml_document<> 文档。

放置您的 xml 文档的文件路径

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

将缓冲区和 xml 文档存储到数组中

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);
于 2016-01-06T11:42:45.710 回答