Hi,

I would really prefer not to extend SerializationInfo. That structure should be generic and not specific to xml. It is also used for other formats. So I am looking for ways to pack the attributes somehow into that structure. My idea is, that we optionally translate the attributes into values, so that we get a structure like that:

name = "head"
    node[0]
            name = "OneGroup"
            typeName = OneGroup
            node[0]
                    name = "OneGroupId"
                    type = string
                    value = "998877"
                    typeName = OneGroupId
                    node[0]
                            name = "OneGroupAttrib"
                            type = string
                            value = "TTT"
    node[1]
            name = "SecondGroup"
            typeName = SecondGroup
            node[0]

So it produces exactly the same structure like this XML:

<?xml version="1.0" encoding="ISO-8859-1"?>
    <head>
    <OneGroup>
        <OneGroupId>998877
             <OneGroupAttrib>TTT</OneGroupAttrib>
        </OneGroupId>
    </OneGroup>

But is it really a problem? What do you think?


Tommi





Am 13.11.2014 um 14:28 schrieb Raphael Fuchs:
Hi Tommi,

thank you for your reply!

Here is an example which is in a format I would like to parse in real life:
-----------------------------------------------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<head>
<OneGroup>
    <OneGroupId OneGroupAttrib="TTT">998877</OneGroupId>
</OneGroup>
<SecondGroup>
<TheField attribNameA="AAA" attribNameB="BBB">someValueofTheField</TheField> <InnerGroup attribName1="AttrContent" attribName2="SecondAttribContent">
        <TagName>TATATA</TagName>
    </InnerGroup>
</SecondGroup>
</head>
-----------------------------------------------------------------

With the current cxxtools implementation it would look like this:
-----------------------------------------------------------------
name = "head"
node[0]
        name = "OneGroup"
        typeName = OneGroup
        node[0]
                name = "OneGroupId"
                type = string
                value = "998877"
                typeName = OneGroupId
node[1]
        name = "SecondGroup"
        typeName = SecondGroup
        node[0]
                name = "TheField"
                type = string
                value = "someValueofTheField"
                typeName = TheField
        node[1]
                name = "InnerGroup"
                typeName = InnerGroup
                node[0]
                        name = "TagName"
                        type = string
                        value = "TATATA"
                        typeName = TagName
name = "OneGroup"
typeName = OneGroup
node[0]
        name = "OneGroupId"
        type = string
        value = "998877"
        typeName = OneGroupId
name = "SecondGroup"
typeName = SecondGroup
node[0]
        name = "TheField"
        type = string
        value = "someValueofTheField"
        typeName = TheField
node[1]
        name = "InnerGroup"
        typeName = InnerGroup
        node[0]
                name = "TagName"
                type = string
                value = "TATATA"
                typeName = TagName
-----------------------------------------------------------------


How could OneGroupId be reflected to see that it has
- an attribute with typeName "OneGroupAttrib" and value "TTT"
- and a value of 998877?

Suggestion:
     node[0]
                name = "OneGroupId"
                type = string
                value = "998877"
                typeName = OneGroupId
                attributes = {[OneGroupAttrib, TTT]}


How could InnerGroup be reflected to see that it has
- an attribute with typeName "attribName1" and value "AttrContent"
- a second attribute with typeName "attribName2" and value "SecondAttribContent"
- and a Tag with typename "TagName" and content "TATATA"

 node[1]
                name = "InnerGroup"
                typeName = InnerGroup
attributes = { [attribName1,AttrContent] , [attribName2,SecondAttribContent] }
                node[0]
                        name = "TagName"
                        type = string
                        value = "TATATA"
                        typeName = TagName

Since the attributes are never hierachical, a good way could be to return the attribues in a new function like this "map<string, string> getAttributes()".

What do you think?

Best regards,
Raphael




Am 12.11.2014 um 18:54 schrieb Tommi Mäkitalo:
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]  
<mailto:[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]  
<mailto:[email protected]>
https://lists.sourceforge.net/lists/listinfo/tntnet-general


--
Comyno Ltd.
Mainzer Landstrasse 46
60325 Frankfurt

www.comyno.com  <http://www.comyno.com>



------------------------------------------------------------------------------
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

------------------------------------------------------------------------------
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

Reply via email to