cereal
cereal copied to clipboard
parse ![CDATA[gh_67d6c2f2d56e]] is empty
when i parse xml,the result is empty.other way,in fact,the rapidxml can do it by use "firstnode()->firstnode()->value()".
You need to provide a minimal example if you want any help with your issue. Double check the documentation and make sure you're using cereal the way it is intended to be used. If you are parsing something cereal did not generate, it may not read correctly.
You need to provide a minimal example if you want any help with your issue. Double check the documentation and make sure you're using cereal the way it is intended to be used. If you are parsing something cereal did not generate, it may not read correctly.
use "cereal":
#include <string>
#include <sstream>
#include <iostream>
#define CEREAL_XML_STRING_VALUE "xml"
#include <cereal/archives/xml.hpp>
int main(int argc, char *argv[])
{
std::string s = "<xml><ToUserName><![CDATA[gh_67d6c2f2d56e]]></ToUserName></xml>";
try
{
std::string toUserName;
{
std::stringstream ss;
ss << s;
cereal::XMLInputArchive archive(ss);
archive(cereal::make_nvp("ToUserName", toUserName));
}
std::cout << "ToUserName:" << toUserName << std::endl;
}
catch (const std::exception ex)
{
std::cout << "ex:" << ex.what();
}
return 0;
}
result: ToUserName:
use "rapidxml":
#include <string>
#include <iostream>
#include <rapidxml.hpp>
int main(int argc, char *argv[])
{
std::string s = "<xml><ToUserName><![CDATA[gh_67d6c2f2d56e]]></ToUserName></xml>";
try
{
rapidxml::xml_document<> doc;
doc.parse<0>(s.data());
rapidxml::xml_node<> *root = doc.first_node("xml");
if (root)
{
rapidxml::xml_node<> *children = root->first_node("ToUserName");
std::string toUserName = children->first_node()->value();
std::cout << "ToUserName:" << toUserName << std::endl;
}
}
catch (const std::exception ex)
{
std::cout << "ex:" << ex.what();
}
return 0;
}
result: ToUserName:gh_67d6c2f2d56e