我想在变量字符串中解析xml响应。没有make xml文件。
我正在使用C ++ RestSDK。
pplx::task<void> Azure::GetTranslateText(utility::string_t ocrText, utility::string_t &transText)
{
auto client = http_client{ U("https://api.microsofttranslator.com/V2/Http.svc") };
uri_builder query;
query.set_path(U("/Translate"));
query.append_query(U("appid"), appid);
query.append_query(U("text"), ocrText);
query.append_query(U("from"), U("en"));
query.append_query(U("to"), U("ko"));
auto path_query_fragment = query.to_string();
return client.request(methods::GET, path_query_fragment).then([&](http_response response)
{
auto bodyStream = response.body();
concurrency::streams::stringstreambuf sbuffer;
auto& target = sbuffer.collection();
bodyStream.read_to_end(sbuffer).get();
transText = utility::conversions::to_string_t(target);
});
}
xml响应在transText中。
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/"/>translated text</string>
答案 0 :(得分:0)
我发现如何在没有xml文档的情况下解析。 使用tinyxml2。
谢谢大家:D
tinyxml2::XMLDocument doc;
doc.Parse(target.c_str());
tinyxml2::XMLElement *elem = doc.FirstChildElement("string");
transText = utility::conversions::to_string_t(elem->GetText());