Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

omit xml declaration when saving xml with boost

Is it possible, via the xml_writer_settings used as third parameter in the write_xml call, to omit the xml declaration when the function saves the xml? I mean, I would like not to have the initial "xml version="blah" encoding="blah blah" part. I'm searching the internet but I still haven't found an answer. How to do it?

like image 708
Magallo Avatar asked Apr 17 '13 10:04

Magallo


2 Answers

Yes, it is possible, but you'll need to call the function 'write_xml_element' directly. Here is an example with boost 1.49:

using namespace boost::property_tree;
ptree pt;
...
write_xml_element(std::cout,ptree::key_type(),pt,-1,xml_writer_settings<ptree::key_type::value_type>());

Of course. you can replace the standard output with std::ofstream or any other output stream you want.

like image 197
Stamen Rakov Avatar answered Nov 03 '22 00:11

Stamen Rakov


No, it's not possible. look here for members of xml_writer_settings

And too, write_xml calls write_xml_internal that is (in boost 1.52)

template<class Ptree>
void write_xml_internal(
std::basic_ostream<typename Ptree::key_type::value_type> &stream, 
const Ptree &pt,
const std::string &filename,
const xml_writer_settings<typename Ptree::key_type::value_type> & settings)
{
    typedef typename Ptree::key_type::value_type Ch;
    typedef typename std::basic_string<Ch> Str;
    stream  << detail::widen<Ch>("<?xml version=\"1.0\" encoding=\"")
            << settings.encoding
            << detail::widen<Ch>("\"?>\n");
    write_xml_element(stream, Str(), pt, -1, settings);
    if (!stream)
        BOOST_PROPERTY_TREE_THROW(xml_parser_error("write error", filename, 0));
}
like image 45
ForEveR Avatar answered Nov 03 '22 02:11

ForEveR