如何解析 xml 响应?
How can I parse an xml response?
我想解析变量字符串中的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>
我找到了如何在没有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());
相关文章:
- Cppcheck生成xml转储文件
- 如何在pugixml中获取节点的内部XML
- 如何使用tinyxml2从XML加载父实体和子实体
- boost xml parsingl将xml的路径作为变量发送
- C++RapidXml-使用first_node()遍历以修改XML文件中节点的值
- 使用 Tinyxml 在 xml 中添加一个子子项
- 当服务中的事件被触发时,如何将响应从服务发送回客户端?
- 增强基于 XML class_id的反序列化
- 在 c++ 中使用 vtd-xml 时,如何摆脱 EOFException?
- 防止在C++中选择错误文件时提升 xml 解析器崩溃
- c++ 读取 xml 文件的内容
- C++ 信号和插槽不工作:插槽不响应事件
- 删除 XML 文件中的子节点C++
- NodeJs 服务器充斥着 UDP 广播,不发送响应
- 使用 RapidXML 更新C++中的 XML 节点和属性值
- 如何解析 xml 响应?
- 如何从QT C 中的Web服务中获得XML响应
- 支持SOAP请求/响应的最佳XML解析器
- 作为XML字符串提取请求/响应
- Gsoap,从旧版本迁移- XML响应名称和结构已更改