Hi,

On 09.02.2010, at 20:00, Jan van de Sandt wrote:

Hello,

I have uploaded the package Magritte-XMLSupport to http://source.lukas-renggli.ch/magritteaddons. The package has a dependency on XMLParser from http://www.squeaksource.com/XMLSupport.

thanks for sharing. I'll have some time this weekend to investigate this. 

I have developed this package using "Magritte for Seaside 3.0". But is also works with "Magritte for Seaside 2.8", in this case you need to add the the Grease package from the Seaside 3.0 as an extra dependency.

I don't think there is that much of a difference. I will see. As long as the pier2 for gemstone isn't ready I'll go with magritte for 2.8. Afterwards I'll port it. Than I'll see.

Have a look at the unit tests to see how to use the package. Note that the API is not yet stable. I use it to export and import my Magritte domain objects in a readable format. I'm now working on export & import functionality for Pier using this library, this could lead to changes/improvements in the package API.

Fair enough. I will start to plug it onto a HTTP Interface. I'll send you a status when I have something running.

Btw. how do you do object resolving? Or better do you assume that always the whole object graph is pulled in or is there an update of existing objects? 

Norbert

Jan.



On Tue, Feb 9, 2010 at 1:15 PM, Jan van de Sandt <jvdsandt@gmail.com> wrote:
Hello,

On Tue, Feb 9, 2010 at 12:23 PM, Norbert Hartl <norbert@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@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



--
Jan van de Sandt
gsm: +31 (0)6 3039 5998
_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki