Boost logo

Boost :

From: Matthias Troyer (troyer_at_[hidden])
Date: 2002-11-18 02:56:16


On Monday, November 18, 2002, at 05:54 AM, Robert Ramey wrote:

> From: "Jeff Garland" <jeff_at_[hidden]>
>
>> If there are technical reasons why the library cannot be extended to
>> do this than I would definitely vote to reject. It sounds like that's
>> what you and Robert are saying, but I don't understand why you think
>> this?
>
> I have to admit I have only a cursory knowledge of XML. I bought
> a book just consider this question. When I tried to envision rendering
> things like stl containers of polymorphic pointers to objects
> with diamond inheritance so of which are repeated into XML
> my imagination failed me. Oh then there is the data name - not readily
> available in C++. So I rebuffed requests for assurances that
> this system can be extended to XML.

Nobody requires the data name to be available in an XML file: the
output is fully defined by the user of the library - and the user of
course knows the name of his variable if that's what he wants to write
into the XML file. There are however other problems.

Let me give one example: we store parameters in a class

typedef std::map<std::string,std::string> ParameterMap

Actually the second template parameter is a more complex class, but for
the sake of this example above is a valid simplification. I write that
into XML as e.g.:

ParameterMap m;
m["L"]="10";
m["T"]="1.0"

gets converted into:

<PARAMETERS>
   <PARAMETER name="L">10</PARAMETER>
   <PARAMETER name="L">10</PARAMETER>
</PARAMETERS>

If instead of typdef-ing ParameterMap as a std::map, I derive
ParameterMap from it then I can easily write a save and load function
to write and read that output. Thus XML can be included.

There is however the problem that I cannot just write

for (ParameterMap::const_iterator it=m.begin();it!=m.end();++it)
   ar << *it;

since the default serializing of a std::pair does not give my my
PARAMETER element above. Instead I have to write things explicitly:

for (ParameterMap::const_iterator it=m.begin();it!=m.end();++it)
   ar << "<PARAMETER name="\"" << it->first
    << "\">" << it->second << "</PARAMETER>\n";

and reading is more involved.

For these reasons I would not use the serialization library for XML
I/O. We are currently working on a simple XML I/O system to fulfill the
need of serialization into XML, but it cannot actually profit from the
serialization library. We arehesitant do not want to post it to boost,
even when the documentation is finished, since for now it does not
support Unicode (as required by XML) but just plain ASCII.

While XML output is thus clearly possible in the serialization library,
the library is clearly not the optimal choice if you have to write or
read XML

Best regards,

Matthias


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk