从xml文件输入并使用rapidxml进行解析

Input from xml file and parsing using rapidxml

本文关键字:rapidxml xml 文件 输入      更新时间:2023-10-16

我正在尝试使用c++使用rapidxml做类似的事情

xml_document<> doc; 
ifstream myfile("map.osm"); 
doc.parse<0>(myfile); 

并接收以下错误

此行有多个标记-无效的参数"候选者为:void parse(char*)"-无法解析符号"parse"

文件大小可以高达几百万字节。

请帮助

您必须按照官方文档中的规定,首先将文件加载到以null结尾的char缓冲区中。

http://rapidxml.sourceforge.net/manual.html#classrapidxml_1_1xml__document_8338ce6042e7b04d5a42144fb446b69c_18338ce6042e7b04d5a42144fb446b69c

只需将文件的内容读取到一个char数组中,并使用该数组传递给xml_document::parse()函数。

如果您使用的是ifstream,您可以使用以下方法将整个文件内容读取到缓冲区

 ifstream file ("test.xml");
 if (file.is_open())
 {
    file.seekg(0,ios::end);
    int size = file.tellg();
    file.seekg(0,ios::beg);
    char* buffer = new char [size];
    file.read (buffer, size);
    file.close();
    // your file should now be in the char buffer - 
    // use this to parse your xml     
    delete[] buffer;
 }

请注意,我没有编译上面的代码,只是根据记忆写的,但这是大致的想法。查看ifstream的文档以了解确切的详细信息。无论如何,这应该会帮助你开始。