cereal icon indicating copy to clipboard operation
cereal copied to clipboard

parse ![CDATA[gh_67d6c2f2d56e]] is empty

Open yk0211 opened this issue 3 years ago • 2 comments

when i parse xml,the result is empty.other way,in fact,the rapidxml can do it by use "firstnode()->firstnode()->value()".

yk0211 avatar Jan 21 '22 10:01 yk0211

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.

AzothAmmo avatar Jan 30 '22 02:01 AzothAmmo

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

yk0211 avatar Feb 16 '22 11:02 yk0211