2015-10-30 01:46:56 +08:00
|
|
|
#include <sstream>
|
|
|
|
|
2015-11-02 01:31:29 +08:00
|
|
|
#include <xlnt/serialization/xml_serializer.hpp>
|
|
|
|
#include <xlnt/serialization/xml_document.hpp>
|
|
|
|
#include <xlnt/serialization/xml_node.hpp>
|
2015-10-30 01:46:56 +08:00
|
|
|
|
|
|
|
#include "detail/include_pugixml.hpp"
|
2015-10-31 06:54:04 +08:00
|
|
|
#include "detail/xml_document_impl.hpp"
|
|
|
|
#include "detail/xml_node_impl.hpp"
|
2015-10-30 01:46:56 +08:00
|
|
|
|
2015-10-31 06:54:04 +08:00
|
|
|
namespace xlnt {
|
2015-10-30 01:46:56 +08:00
|
|
|
|
2015-10-31 06:54:04 +08:00
|
|
|
std::string xml_serializer::serialize(const xml_document &xml)
|
2015-10-30 01:46:56 +08:00
|
|
|
{
|
2015-10-31 06:54:04 +08:00
|
|
|
std::ostringstream ss;
|
|
|
|
xml.d_->doc.save(ss, " ", pugi::format_default, pugi::encoding_utf8);
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2015-10-31 06:54:04 +08:00
|
|
|
return ss.str();
|
2015-10-30 01:46:56 +08:00
|
|
|
}
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2015-10-31 06:54:04 +08:00
|
|
|
xml_document xml_serializer::deserialize(const std::string &xml_string)
|
|
|
|
{
|
|
|
|
xml_document doc;
|
|
|
|
doc.d_->doc.load(xml_string.c_str());
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2015-10-31 06:54:04 +08:00
|
|
|
return doc;
|
2015-10-30 01:46:56 +08:00
|
|
|
}
|
|
|
|
|
2015-10-31 06:54:04 +08:00
|
|
|
std::string xml_serializer::serialize_node(const xml_node &xml)
|
2015-10-30 01:46:56 +08:00
|
|
|
{
|
|
|
|
pugi::xml_document doc;
|
2015-10-31 06:54:04 +08:00
|
|
|
doc.append_copy(xml.d_->node);
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2015-10-30 01:46:56 +08:00
|
|
|
std::ostringstream ss;
|
|
|
|
doc.save(ss);
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2015-10-30 01:46:56 +08:00
|
|
|
return ss.str();
|
|
|
|
}
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2015-10-30 01:46:56 +08:00
|
|
|
} // namespace xlnt
|