c++ - 从 xml 文件输入并使用 rapidxml 解析

标签 c++ eclipse rapidxml

我正在尝试使用 c++ 使用 rapidxml 做这样的事情

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

并收到以下错误

此行有多个标记 - 无效参数 'Candidates are: void parse(char *) ' - 符号 'parse' 无法解析

文件大小可达几兆字节。

请帮忙

最佳答案

您必须首先按照官方文档中的说明将文件加载到以空字符结尾的字符缓冲区中。

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

只需将文件内容读入一个字符数组,然后使用该数组传递给 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 的文档以了解确切的详细信息。无论如何,这应该可以帮助您入门。

关于c++ - 从 xml 文件输入并使用 rapidxml 解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11810187/

相关文章:

c++ - 从 ICMP 报文访问 UDP

c++ - 如何解决 [Linker Error] Unresolved external in Borland C++ builder 6

eclipse 中的 java.lang.UnsupportedClassVersionError

c - C 的 Eclipse : Launch failed no binaries

c++ - RapidXML 的编译错误

c++ - RapidXML:段错误; first_node() 返回 NULL

c++ - 如何轻松地用CGAL在球体上构造Voronoi图?

C++ 继承 - 为什么调用父方法?

java - 如何在Eclipse中查看JRE的源代码?

一定时间后 C++ rapidxml 访问冲突(visual studio 2013)