Hello
I'm using boost property_tree with the variant data type:
typedef boost::variant<std::string, std::vector<std::string> > registry_entry;
i.e I want to store either strings or vectors of strings at each key node. I'm using the inserters and extractors at the bottom of this email (similar to those included in the custom_data.cpp in the property_tree/examples folder). 

Does anyone know how I can write the tree out in xml format? The provided write_xml method can only handle property trees of string data type. Is there anyway to either tweak the code (e.g. modify the inserter and extractors) or wrap the variant class such that property_tree::write_xml will correctly render the tree as xml?

Regards
Craig


// Custom extractor - converts data from boost::any to Type
template<class Type>
struct pt_extractor
{
    inline bool operator()(const boost::any &data,
                           Type &extracted,
                           const std::locale &loc) const
    {
        extracted = boost::any_cast<Type>(data);
        return true;    // Success
    }
};

// Custom inserter - converts data from Type to boost::any
template<class Type>
struct pt_inserter
{
    inline bool operator()(boost::any &data,
                           const Type &to_insert,
                           const std::locale &loc) const
    {
        data = to_insert;
        return true;    // Success
    }
};

// Custom property_tree traits - using custom extractor and inserter
template<class Ch>
struct pt_traits
{

    // Character type to be used by ptree keys
    typedef Ch char_type;

    // Key type to be used by ptree
    typedef std::basic_string<Ch> key_type;

    // Data type to be used by ptree
    typedef boost::any data_type;
   
    // Extractor to be used by ptree
    template<class Type>
    struct extractor: public pt_extractor<Type> { };

    // Inserter to be used by ptree
    template<class Type>
    struct inserter: public pt_inserter<Type> { };

    // Key comparison function
    inline bool operator()(const key_type &key1,
                           const key_type &key2) const
    {
                return _stricmp(key1.c_str(), key2.c_str()) < 0;
    }

};

typedef boost::property_tree::basic_ptree<pt_traits<char> > pt_rep;
typedef boost::variant<std::string, std::vector<std::string> > registry_entry;




******************************************************************************************
This communication is sent by the Standard Bank Plc or one of its affiliates
The registered details of Standard Bank Plc are:
Registered in England No. 2130447, Registered Office 25 Dowgate Hill London EC4R 2SB
Authorised and Regulated by the Financial Services Authority.

More information on Standard Bank is available at www.standardbank.com

Everything in this email and any attachments relating to the official business
of Standard Bank Group Limited and any or all subsidiaries, ("the Company"), is
proprietary to the Company. It is confidential, legally privileged and protected
by relevant laws. The Company does not own and endorse any other content.
Views and opinions are those of the sender unless clearly stated as being
that of the Company.

The person or persons addressed in this email are the sole authorised
recipient. Please notify the sender immediately if it has unintentionally,
or inadvertently reached you and do not read, disclose or use the content
in any way and delete this e-mail from your system.

The Company cannot ensure that the integrity of this email has been
maintained nor that it is free of errors, virus, interception or interference.
The sender therefore does not accept liability for any errors or omissions
in the contents of this message which arise as a result of e-mail transmission.
If verification is required please request a hard-copy version. This message
is provided for informational purposes and should not be construed as a
solicitation or offer to buy or sell any securities or related financial instruments.
******************************************************************************************