Serialisation of extLst without namespace support

-- roundtripping namespaces requires modifications of the parser used for the entire worksheet as there does not appear to be a way to track the namespace changes without listening/registering for the event. This (ofcourse) breaks lots of other things...
This commit is contained in:
Crzyrndm 2018-06-24 23:08:23 +12:00
parent a347d9c05d
commit 840d1bcefc
3 changed files with 12 additions and 10 deletions

View File

@ -49,14 +49,14 @@ public:
public:
ext(xml::parser &parser);
ext(const uri& ID, const std::string& serialised);
void serialise(xml::serializer &serialiser);
void serialise(xml::serializer &serialiser, const std::string& ns);
uri extension_ID_;
std::string serialised_value_;
};
ext_list() = default; // default ctor required by xlnt::optional
explicit ext_list(xml::parser &parser);
void serialize(xml::serializer &serialiser, std::string nmsp);
void serialize(xml::serializer &serialiser, const std::string& ns);
void add_extension(const uri &ID, const std::string &element);

View File

@ -2998,6 +2998,11 @@ void xlsx_producer::write_worksheet(const relationship &rel)
}
}
if (ws.d_->extension_list_.is_set())
{
ws.d_->extension_list_.get().serialize(*current_part_serializer_, xmlns);
}
write_end_element(xmlns, "worksheet");
if (!worksheet_rels.empty())

View File

@ -9,7 +9,7 @@ namespace {
xlnt::uri roundtrip(xml::parser& p, xml::serializer &s)
{
xlnt::uri ext_uri;
int nest_level = 0; // ext element already opened on entry
int nest_level = 0;
while (nest_level > 0 || (p.peek() != xml::parser::event_type::end_element && p.peek() != xml::parser::event_type::eof))
{
switch (p.next())
@ -64,8 +64,6 @@ namespace xlnt {
ext_list::ext::ext(xml::parser &parser)
{
//parser.next_expect(xml::parser::start_element, "ext");
//extension_ID_ = uri(parser.attribute("uri"));
std::ostringstream serialisation_stream;
xml::serializer s(serialisation_stream, "", 0);
extension_ID_ = roundtrip(parser, s);
@ -76,7 +74,7 @@ ext_list::ext::ext(const uri &ID, const std::string &serialised)
: extension_ID_(ID), serialised_value_(serialised)
{}
void ext_list::ext::serialise(xml::serializer &serialiser)
void ext_list::ext::serialise(xml::serializer &serialiser, const std::string& ns)
{
std::istringstream ser(serialised_value_);
xml::parser p(ser, "", xml::parser::receive_default);
@ -85,7 +83,6 @@ void ext_list::ext::serialise(xml::serializer &serialiser)
ext_list::ext_list(xml::parser &parser)
{
parser.content(xml::parser::content_type::mixed);
// begin with the start element already parsed
while (parser.peek() == xml::parser::start_element)
{
@ -94,12 +91,12 @@ ext_list::ext_list(xml::parser &parser)
// end without parsing the end element
}
void ext_list::serialize(xml::serializer &serialiser, std::string namesp)
void ext_list::serialize(xml::serializer &serialiser, const std::string& namesp)
{
serialiser.start_element("extLst", namesp);
serialiser.start_element(namesp, "extLst");
for (auto &ext : extensions_)
{
ext.serialise(serialiser);
ext.serialise(serialiser, namesp);
}
serialiser.end_element();
}