0

I want to parse xml response in variable string. no make xml file.

I'm using 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 is in transText.

<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/"/>translated text</string>
M-AHHH
  • 1
  • 5

1 Answers1

0

I found how to parse without xml document. using tinyxml2.

Thanks everyone :D

    tinyxml2::XMLDocument doc;
    doc.Parse(target.c_str());

    tinyxml2::XMLElement *elem = doc.FirstChildElement("string");
    transText = utility::conversions::to_string_t(elem->GetText());
M-AHHH
  • 1
  • 5