Met vriendelijke groet / With kind regards / mit besten Grüßen,
Coen Schalkwijk Software Engineer
coen.schalkwijk@rtl.nl mailto:coen.schalkwijk@rtl.nl
coen@rtlinteractief.nl mailto:coen@rtlinteractief.nl
+31 (0)35 671 8915
Hi All,
Creating the XML is no problem, I build a nice method that easily and neatly builds a typed XML. Now I'm working on the translation back to pike and that's when I ran into some 'issues', having mainly to do with translating XML to an object. Currently I have only basic types in the objects I want to store (arrays/mappings with int/string keys and values) which can easily translate back to the pike equivalents (provided I use some less pretty code for handling mapping and array creation). but I'd like to have the subject of object XML serialization covered before the expected function request arises :)
If, a generic type of, annotation was available/possible, it would be far more easier to accomplish this (/serialization to any type of output) without having to know or store everything about the objects involved.
Greetings,
Coen
On 12-1-2011 19:44, Johan Björklund wrote:
On 12/01/11 17:01, Coen Schalkwijk wrote:
Thanks for your suggestion. Is it possible in pike to do/use/consume something like 'they' do in dotNET:
[XMLNode name="A"] classA{ [XMLNode name="aVar"] string a; [XMLNode name="cookieCount"] int b; }
There is no real need for this when it is so easy to look into objects, iterate, etc.
To map special names to variables, just use a mapping:
mapping XMLNames = ([ classA : ([ "a" : "aVar", "b" : "cookieCount" ]), classB : ([ "a" : "aVar", "b" : "somethingElse" ]) ]);
mapping default_XMLNames = ([ "a" : "aVar" ]);
object o = get_object(); mapping o_xml_names = XMLNames[object_program(o)] || default_XMLNames;
foreach (o; string var_name; mixed val) { string name = o_xml_names[var_name]; if (!name) continue; /* add to xml */ }
This way seems preferable to editing and cluttering old code with annotations.
There is also Program.implements() which is probably good to use.