Hi All,
I would like to build an XML structure which was defined by a third party.
It should look like
<?xml version="1.0" encoding="utf-8"?>
<AMessage>
<Header>
<headerField>ttt</headerField>
</Header>
<Body>
<bodyField>aaa</bodyField>
</Body>
</AMessage>
The result I get using cxxtools is at the moment:
<?xml version="1.0" encoding="UTF-8"?>
<AMessage category="struct">
<headerField type="string">ttt</headerField>
<bodyField type="string">aaa</bodyField>
</AMessage>
My questions are:
- How can I insert Header and Body into the hierarchy?
- Can I get rid of 'category="struct"'?
- Can I get rid of 'type="string"'?
And in general what is the best way to manipulate the result when I need
changes in the format?
My code looks like this:
====================
// Business Object
struct AMessage {
std::string headerField;
std::string bodyField;
};
// Operator for the serializer.
void operator<<= (cxxtools::SerializationInfo &si, const AMessage& obj)
{
si.addMember("headerField") <<= obj.headerField;
si.addMember("bodyField") <<= obj.bodyField;
}
// Serialize to xml
main()
{
AMessage msg;
msg.headerField = "ttt";
msg.bodyField = "aaa";
std::ostringstream xmlstream;
cxxtools::xml::XmlSerializer serializer(xmlstream);
serializer.serialize(msg, "AMessage");
serializer.finish();
log_info(xmlstream.str());
}
Kind Regards,
Andreas
------------------------------------------------------------------------------
Time is money. Stop wasting it! Get your web API in 5 minutes.
www.restlet.com/download
http://p.sf.net/sfu/restlet
_______________________________________________
Tntnet-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tntnet-general