1

这是我一直在尝试的:

pugi::xml_document doc;

pugi::xml_parse_result result = doc.load_file("Book.xml"); // need to change this

std::cout << "Load result: " << result.description() << ", mesh name: " << doc.child("mesh").attribute("name").value() << std::endl;

我想做这样的事情:

URL url;
url = new URL("http://.....");
URLConnection ucon = url.openConnection();
ucon.connect();
pugi::xml_parse_result result = doc.load_file(url.openStream()); // need to change this

编辑1:

显然这是不可能的。 http://code.google.com/p/pugixml/issues/detail?id=116

那么我应该如何前进呢?

4

1 回答 1

1

我使用 cURL 库从 URL 获取内容并将其保存为字符串,如下所示:

CURL *curl;
CURLcode res;
std::string readBuffer;

curl = curl_easy_init();
if(curl) {
    curl_easy_setopt(curl, CURLOPT_URL, "http:...");
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
    res = curl_easy_perform(curl);
    curl_easy_cleanup(curl);
}

然后我解析了字符串中包含的数据:

pugi::xml_document doc;
pugi::xml_parse_result result = doc.load(readBuffer.c_str());

十分简单 :-)

于 2012-07-01T06:56:41.740 回答