Hello,
On Tue, Feb 9, 2010 at 12:23 PM, Norbert Hartl <norbert(a)hartl.name> wrote:
Hi Jan,
that looks great. I really would like to have a look at the code. May I
have a few questions upfront:
Ok, I will upload the code this evening.
- I assume MAXMLTestPerson is the class name of the
instance you are
serializing. I would avoid exposing an implementation detail to the outside
world. Do you use that information on parse time? I would expect that you
know how to parse the top level object (by service context etc.). Regarding
references the detail about what to parse is in MAReferenceDescription you
are using for e.g. the address. If this is all right you could go with
<Person> and <Address>. This would make it possible to parse the XML with a
subclass of e.g. MAXMLTestPerson
Yes MAXMLTestPerson is the class name. This was the easiest way to
serialize
instances of classes that have the same Magritte description. This
behaviour is implemented in MAXMLWriter, a subclass of MAWriter. It can be
easily customized by creating your own subclass of this visitor.
- You inlined the address instance into the person. Is
this exchangable?
I'm not sure I'll go for REST but if yes then I would like to do it by
reference. Let's say <adress
id="http://my.service.srv/address/12345"> ...
The current implementation inlines the first occurrence of an object and
adds an id
attribute. If an object occurs multiple times than a reference to
the id is inlined. For example:
Smalltalk:
personWithFriendsCycle
| bill john carl |
bill := MAXMLTestPerson new
name: 'Bill';
yourself.
john := MAXMLTestPerson new
name: 'John';
yourself.
carl := MAXMLTestPerson new
name: 'Carl';
friends: (OrderedCollection with: bill with: john);
yourself.
bill friends: (OrderedCollection with: john with: carl).
john friends: (OrderedCollection with: bill with: carl).
^carl
XML:
<MAXMLTestPerson id="1">
<name>Carl</name>
<friends>
<OrderedCollection>
<MAXMLTestPerson id="2">
<name>Bill</name>
<friends>
<OrderedCollection>
<MAXMLTestPerson id="3">
<name>John</name>
<friends>
<OrderedCollection>
<MAXMLTestPerson ref="2"/>
<MAXMLTestPerson ref="1"/>
</OrderedCollection>
</friends>
</MAXMLTestPerson>
<MAXMLTestPerson ref="1"/>
</OrderedCollection>
</friends>
</MAXMLTestPerson>
<MAXMLTestPerson ref="3"/>
</OrderedCollection>
</friends>
</MAXMLTestPerson>
- What do you do with the date field in birthday? Is
this a fixed format or
do you specify this over magritte?
This is also implemented using the MAXMLWriter visitor and can be easily
customized
per description class.
Jan.
On 09.02.2010, at 11:59, Jan van de Sandt wrote:
Hello Norbert,
I have developed some code to serialize object to XML and visa versa using
their Magritte descriptions. It is not completely finished yet but for
standard scenario's it works fine.
Here an example where an instance of MAXMLTestPerson is serialized to XML.
<MAXMLTestPerson>
<name>Bill Gates</name>
<address>
<MAXMLTestAddress>
<city>Amsterdam</city>
<street>Mainstreet</street>
</MAXMLTestAddress>
</address>
<birthDate>1966-10-20</birthDate>
</MAXMLTestPerson>
It can be de-serialized using MAXMLParser:
MAXMLParser parse: self personWithAddressXML readStream.
The serialization process can be customized. I still have to add proper
error handling. My intention was to add it to the Magritte add-ons
repository when the error handling was fully working. If you want I can add
it sooner so you can have a look.
Jan.
On Tue, Feb 9, 2010 at 11:22 AM, Norbert Hartl <norbert(a)hartl.name> wrote:
Hi,
at the moment I'm thinking about a new project. The project will need a
Web API to communicate with an iphone. To me it is quite obvious to
implement the API part as a request handler. But when it comes to generation
of e.g. XML I'm not sure what is the best way to do.
Sure, the seaside way to do it is to create my own canvas and every object
needs to draw itself onto the canvas. But then I have magritte and a lot
could be done automatically. Using xpath in the descriptions I could use
Pastell to deserialize objects. To produce the output there could be a
similar way. This would be some kind of XML binding then.
I wanted to ask if there is anything already available that could help me
on my way or if there dedicated ideas how to solve this in seaside.
thanks in advance,
Norbert
_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki
--
Jan van de Sandt
gsm: +31 (0)6 3039 5998
_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki
_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki
--
Jan van de Sandt
gsm: +31 (0)6 3039 5998