Reputation: 1741
I'm trying to use pugixml to modify xml configuration, created through boost::serialization and used by other application so i need to change only few fragments of document and leave all other parts the same.
Some nodes may store empty strings in the form of <value></value>
. After load & save (with pugi) this nodes changes into <value />
. After this boost::serialization cannot parse such file.
Load options parse_ws_pcdata_single
and parse_ws_pcdata
works only if there is white space between.
I didn't found saving option for saving empty nodes in form <value></value>
too.
Is there any way to preserve opening & closing tags with zero text between?
Upvotes: 3
Views: 1232
Reputation: 178
If someone still comes across this question, you don't need to change the source. Simply use this flag when writing your tree:
pugi::format_no_empty_element_tags
See the docs in https://pugixml.org/docs/manual.html#saving.options
Upvotes: 1
Reputation: 584
Pugixml has been updated and the answer to this has changed
This is for Pugixml version 1.6
To generate closing tags for all nodes,
modify pugixml.cpp: line 3503
from
PUGI__FN bool node_output_start(xml_buffered_writer& writer, xml_node_struct* node, unsigned int flags)
to
PUGI__FN void node_output_end(xml_buffered_writer& writer, xml_node_struct* node);
PUGI__FN bool node_output_start(xml_buffered_writer& writer, xml_node_struct* node, unsigned int flags)
modify pugixml.cpp: line 3516
from
writer.write(' ', '/', '>');
to
writer.write('>');
node_output_end(writer, node);
Upvotes: 2
Reputation: 9404
There is no readily available option.
It is easy to change pugixml to output the XML that you need (probably easier than fixing boost::serialization...):
in pugixml.cpp around line 3249, there's this code:
else if (!node.first_child())
writer.write(' ', '/', '>', '\n');
Just remove these two lines if you're using indented formatting (if you're using format_raw there's similar code slightly above).
Upvotes: 2