Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ namespace boost { namespace property_tree { namespace xml_parser
case node_element:
{
// Create node
Ptree &pt_node = pt.push_back(std::make_pair(node->name(),
Ptree()))->second;
Ptree &pt_node = pt.push_back(std::make_pair(
(node->name() == const_cast<Ch *>(
"nullkey-3cb6534e-d358-4705-9e74-fee06453661e")
? const_cast<Ch *>("") : node->name()),
Ptree()))->second;

// Copy attributes
if (node->first_attribute())
Expand Down
11 changes: 8 additions & 3 deletions include/boost/property_tree/detail/xml_parser_write.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/detail/xml_parser_utils.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/optional/optional.hpp>
#include <string>
#include <ostream>
Expand Down Expand Up @@ -73,6 +74,7 @@ namespace boost { namespace property_tree { namespace xml_parser
typedef typename Ptree::key_type::value_type Ch;
typedef typename Ptree::key_type Str;
typedef typename Ptree::const_iterator It;
const typename Ptree::key_type &nullkey = "nullkey-3cb6534e-d358-4705-9e74-fee06453661e";

bool want_pretty = settings.indent_count > 0;
// Find if elements present
Expand All @@ -97,7 +99,8 @@ namespace boost { namespace property_tree { namespace xml_parser
if (indent >= 0)
{
write_xml_indent(stream,indent,settings);
stream << Ch('<') << key <<
stream << Ch('<') << (key.empty() ?
lexical_cast<typename Ptree::key_type>(nullkey) : key) <<
Ch('/') << Ch('>');
if (want_pretty)
stream << Ch('\n');
Expand All @@ -110,7 +113,8 @@ namespace boost { namespace property_tree { namespace xml_parser
{
// Write opening brace and key
write_xml_indent(stream,indent,settings);
stream << Ch('<') << key;
stream << Ch('<') << (key.empty() ?
lexical_cast<typename Ptree::key_type>(nullkey) : key);

// Write attributes
if (optional<const Ptree &> attribs = pt.get_child_optional(xmlattr<Str>()))
Expand Down Expand Up @@ -168,7 +172,8 @@ namespace boost { namespace property_tree { namespace xml_parser
{
if (has_elements)
write_xml_indent(stream,indent,settings);
stream << Ch('<') << Ch('/') << key << Ch('>');
stream << Ch('<') << Ch('/') << (key.empty() ?
lexical_cast<typename Ptree::key_type>(nullkey) : key) << Ch('>');
if (want_pretty)
stream << Ch('\n');
}
Expand Down
6 changes: 6 additions & 0 deletions test/test_xml_parser_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ void test_xml_parser()
3, umlautsize<char_type>(), 12
);

generic_parser_test_ok<Ptree, ReadFuncWS, WriteFuncWS>
(
ReadFuncWS(), WriteFuncWS(), ok_data_6, NULL,
"testok6a.xml", NULL, "testok6aout.xml", 4, 1, 2
);

generic_parser_test_error<Ptree, ReadFuncWS, WriteFuncWS, xml_parser_error>
(
ReadFuncWS(), WriteFuncWS(), error_data_1, NULL,
Expand Down
7 changes: 7 additions & 0 deletions test/xml_parser_test_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,13 @@ const char ok_data_5[] =
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" /*39 chars*/
"<doc>\xC3\xA4</doc>";

const char *ok_data_6 =
"<a>"
"<nullkey-3cb6534e-d358-4705-9e74-fee06453661e>"
"<b>c</b>"
"</nullkey-3cb6534e-d358-4705-9e74-fee06453661e>"
"</a>";

// Erroneous
const char *error_data_1 =
"a"; // bogus character
Expand Down