Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Creating XML with ticpp can be very verbose #45

Open
GoogleCodeExporter opened this issue Mar 17, 2015 · 10 comments
Open

Creating XML with ticpp can be very verbose #45

GoogleCodeExporter opened this issue Mar 17, 2015 · 10 comments

Comments

@GoogleCodeExporter
Copy link

The current TinyXML++ API requires that each XML node is created, and added
to a parent, explicitly.  As such, it can quickly become verbose.  Consider
the following example:

    Element measurements("measurements");
    Element tbr("TotalBytesReceived");
    tbr.SetAttribute("displayName", "Total Bytes Received");
    tbr.SetText(12);
    Element tbp("TotalBytesProcessed");
    tbp.SetAttribute("displayName", "Total Bytes Processed");
    tbp.SetText(14);
    Element teb("TotalErroredBytes");
    teb.SetAttribute("displayName", "Total Errored Bytes");
    teb.SetText(42);
    measurements.InsertEndChild(tbr);
    measurements.InsertEndChild(tbp);
    measurements.InsertEndChild(teb);
    root->InsertEndChild(measurements);

That produces the following XML snippet:

    <measurements>
        <TotalBytesReceived displayName="Total Bytes
Received">12</TotalBytesReceived>
        <TotalBytesProcessed displayName="Total Bytes
Processed">14</TotalBytesProcessed>
        <TotalErroredBytes displayName="Total Errored
Bytes">42</TotalErroredBytes>
    </measurements>

Through the use of judicious operator overloading we could have syntax like
the following:

    *root <<
        (Element("measurements")
            << (Element("TotalBytesReceived")("displayName", "Total Bytes
Received") = 12)
            << (Element("TotalBytesProcessed")("displayName", "Total Bytes
Processed") = 14)
            << (Element("TotalErroredBytes")("displayName", "Total Errored
Bytes") = 42));

(I've attached a trivial patch that allows this.)

For me this is a significant improvement.  In particular I the SetAttribute
(operator()()) and SetText (operator=) changes fit well IMO.  I'm less
happy with operator<< inserting a node...I'm still experimenting.

So, generally, the issue is that ticpp is quite verbose and we could
possibly make improvements.  What do you think?

[Also, is it possible to start a discussion board?  This isn't really the
right place to discuss improvements but there doesn't seem to be anywhere
else to communicate!  We intend to use ticpp a fair bit within our company
and I'd like to try and help where I can.]

Original issue reported on code.google.com by [email protected] on 7 Apr 2009 at 2:26

Attachments:

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant