mirror of
https://github.com/tfussell/xlnt.git
synced 2024-03-22 13:11:17 +08:00
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:
parent
a347d9c05d
commit
840d1bcefc
|
@ -49,14 +49,14 @@ public:
|
||||||
public:
|
public:
|
||||||
ext(xml::parser &parser);
|
ext(xml::parser &parser);
|
||||||
ext(const uri& ID, const std::string& serialised);
|
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_;
|
uri extension_ID_;
|
||||||
std::string serialised_value_;
|
std::string serialised_value_;
|
||||||
};
|
};
|
||||||
ext_list() = default; // default ctor required by xlnt::optional
|
ext_list() = default; // default ctor required by xlnt::optional
|
||||||
explicit ext_list(xml::parser &parser);
|
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);
|
void add_extension(const uri &ID, const std::string &element);
|
||||||
|
|
||||||
|
|
|
@ -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");
|
write_end_element(xmlns, "worksheet");
|
||||||
|
|
||||||
if (!worksheet_rels.empty())
|
if (!worksheet_rels.empty())
|
||||||
|
|
|
@ -9,7 +9,7 @@ namespace {
|
||||||
xlnt::uri roundtrip(xml::parser& p, xml::serializer &s)
|
xlnt::uri roundtrip(xml::parser& p, xml::serializer &s)
|
||||||
{
|
{
|
||||||
xlnt::uri ext_uri;
|
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))
|
while (nest_level > 0 || (p.peek() != xml::parser::event_type::end_element && p.peek() != xml::parser::event_type::eof))
|
||||||
{
|
{
|
||||||
switch (p.next())
|
switch (p.next())
|
||||||
|
@ -64,8 +64,6 @@ namespace xlnt {
|
||||||
|
|
||||||
ext_list::ext::ext(xml::parser &parser)
|
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;
|
std::ostringstream serialisation_stream;
|
||||||
xml::serializer s(serialisation_stream, "", 0);
|
xml::serializer s(serialisation_stream, "", 0);
|
||||||
extension_ID_ = roundtrip(parser, s);
|
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)
|
: 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_);
|
std::istringstream ser(serialised_value_);
|
||||||
xml::parser p(ser, "", xml::parser::receive_default);
|
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)
|
ext_list::ext_list(xml::parser &parser)
|
||||||
{
|
{
|
||||||
parser.content(xml::parser::content_type::mixed);
|
|
||||||
// begin with the start element already parsed
|
// begin with the start element already parsed
|
||||||
while (parser.peek() == xml::parser::start_element)
|
while (parser.peek() == xml::parser::start_element)
|
||||||
{
|
{
|
||||||
|
@ -94,12 +91,12 @@ ext_list::ext_list(xml::parser &parser)
|
||||||
// end without parsing the end element
|
// 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_)
|
for (auto &ext : extensions_)
|
||||||
{
|
{
|
||||||
ext.serialise(serialiser);
|
ext.serialise(serialiser, namesp);
|
||||||
}
|
}
|
||||||
serialiser.end_element();
|
serialiser.end_element();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user