0
我想解析變量字符串中的xml響應。沒有make xml文件。如何解析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 response在transText中。
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/"/>translated text</string>
你嘗試過這麼遠嗎? – SirDarius
爲了解析XML,您需要[XML解析器](https://stackoverflow.com/a/9387612/226648)。 –
@SirDarius我試圖使用tinyxml2。 –