Hi Tommi,
this is a cool solution. I tried it and it works perfectly.
Thank you!
Andreas
On 11/15/2014 08:29 PM, Tommi Mäkitalo wrote:
Hi,
I checked in the changes. Now there is a flag "readAttributes" in
XmlDeserializer, which controls whether the attributes should be
converted to values.
Note that the flag defaults to false and must be set before the xml is
actually parsed. There are some ways to call the deserializer. First
possibility:
std::istream& in = ...;
cxxtools::xml::XmlDeserializer d(in);
d.deserialize(myObject);
Here the constructor already parses the xml and setting the flag
"readAttributes" has no effect. So the constructor now receives the
flag as a second parameter:
cxxtools::xml::XmlDeserializer d(in, true);
This sets the flag before reading. This will work.
I also added a default constructor to the deserializer and added
public parse methods, which triggers the parsing. So this is possible:
cxxtools::xml::XmlDeserializer d;
d.readAttributes(true);
d.parse(in);
Or the constructor also takes the flag as parameter:
cxxtools::xml::XmlDeserializer d(true);
d.parse(in);
A nice and short way to do it is to use the deserialize helper function:
in >> cxxtools::xml::Xml(myObject).readAttributes(true);
This will instantiate the deserializer and set the attribute.
The SerializationInfo, which holds the attribute will have a type name
set to "attribute", so that you can even distinguish between sub nodes
and attributes in your deserialization operator if you really want.
You can see the whole thing in action in the new demo
CXXTOOLS/demos/xmlreader.cpp. It is a minimal example where a very
simple xml document with just one node with attributes is read into a
object.
I plan to extend the reading of tntnet.xml to use that flag, Then the
tntnet.xml will get a little shorter. For example to define a mapping
we used:
<mapping>
<target>index@myapp</target>
<url>^/$</url>
</mapping>
When the flag is set, we can change the setting to:
<mapping target="index@myapp" url="^/$" />
Which is much shorter. Note the previous setting will work as well. It
is then just a matter of taste, which one to use. You can even mix both:
<mapping target="index@myapp">
<url>^/$</url>
</mapping>
Looks strange but it will work.
Also setting logging is shorter. Instead of:
<logger>
<category>tntnet</category>
<level>INFO</level>
</logger>
You may write:
<logger category="tntnet" level="INFO"/>
I need to extend log_init also to set that attribute.
Tommi
------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://pubads.g.doubleclick.net/gampad/clk?id=154624111&iu=/4140/ostg.clktrk
_______________________________________________
Tntnet-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tntnet-general
------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk
_______________________________________________
Tntnet-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tntnet-general