Hi,
the xml deserializer does not read XML attributes. So no luck currently.
But we can change it if desired. I've thought about it.
Lets first look at the problem. The deserializer actually converts a xml
structure into a cxxtools::SerializationInfo. The SerializationInfo node
has a value, a name, a type, a category and a vector of nodes. So the
deserializer has to somehow pack all information from the XML structure
into the SerializationInfo.
The name and the type are strings. The category may be Void, Value,
Object or Array. The value is a union which takes a scalar value.
When we have a structure like:
<foo><bar>value</bar></foo>
the serializationinfo will have one subnode with the name "bar" and the
string value "value". The <foo> node may contain the attributes "type"
and "category". The "type" is put into the type field and the category
may have the value "array", "struct" or "value" and is converted to the
enum.
So there is actually nothing, we can put arbitrary attributes into. When
we have:
<foo baz="42"><bar>value</bar></foo>
the deserializer do not know what to do with the attribute "baz" and
hence ignores it.
A solution, which comes into my mind is to add an option into the
deserializer to convert the attributes also to a sub node. When enabled,
the deserializer will convert the above structure into a
SerializationInfo with 2 sub nodes. One with the name "baz" and the
other "bar". But in that case we can't distinguish between a attribute
and a subnode. Maybe we can set the category of the subnode (<bar> in
that case) to Array since it potentially can have other subnodes. We get
an empty array with a name then.
That is quite easy to implement and feel, that it would be useful in the
future.
I know that it is not that easy to understand and for me not that easy
to explain. I hope, that you can see, what I try to achieve.
Tommi
Am 10.11.2014 um 17:45 schrieb Raphael Fuchs:
Hello,
I want to read the following xml with all the fields and attributes:
---------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<rootelement someId="11756">
<subgroup subgroupId="25">
<someString>this is a string</someString>
</subgroup>
</rootelement>
---------------------------------------------------------------------------------------------
But I cannot read the attributes "someId" and "subgroupId".
I tried with the following code that just prints to the logfile:
---------------------------------------------------------------------------------------------
void operator>>= (const cxxtools::SerializationInfo& si, Dummy& fields)
{
size_t count = si.memberCount();
log_info("root: " << si.name <http://si.name>());
for (size_t idx = 0; idx < count; ++idx)
{
// get current field
cxxtools::SerializationInfo oneField = si.getMember(idx);
if (oneField.memberCount() > 0) // it is a group
{
log_info("Group: " << oneField.typeName());
// keep name of current parent in mind
parentName.push(oneField.typeName());
oneField >>= fields;
// get rid of the last groupname
parentName.pop();
}
else
{
std::string value;
oneField.getValue(value);
log_info("Field: " << oneField.typeName() << ": " << value);
}
}
}
---------------------------------------------------------------------------------------------
Could someone give me a hint on how to read the attributes?
Cheers
Raphael
------------------------------------------------------------------------------
_______________________________________________
Tntnet-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tntnet-general
------------------------------------------------------------------------------
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