RE: unmarshalling heterogeneous collections

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

RE: unmarshalling heterogeneous collections

jtuchel
Tamara,

thank you very much. It seems the xpath="child::*" attribute of the anyCollection marshaller was all that was missing.

I must admit I don't really understand why it is needed and makes such a difference. Isn't an anyCollection a collection of whatever there might come along, as long as there is a mapping available for it?

Is there any documentation available (blog posts, white papers or whatever) that could have helped me on this path?

Again, thank you very much for helping me with this,

Joachim


--- original message follows ---


I hope the sample below helps.


schema := '<schemaBindings >
<xmlToSmalltalkBinding name="AnyCollection"
xmlns:xsd="http://www.w3.org/2000/10/XMLSchema"
targetNamespace="urn:point">
<object name="point" smalltalkClass="Point">
 <attribute name="x" ref="xsd:float"/>
 <attribute name="y" ref="xsd:float"/>
</object>
<object name="rectangle" smalltalkClass="Rectangle">
 <element name="origin" ref="point"/>
 <element name="corner" ref="point"/>
</object>
<object name="association" smalltalkClass="Association">
 <attribute name="key" ref="xsd:int"/>
 <attribute name="value" ref="xsd:string"/>
</object>
<object name = "CollectionHolder" smalltalkClass="ValueHolder">
<anyCollection name="value" setSelector="setValue:" xpath="child::*"/>
</object>
</xmlToSmalltalkBinding>
</schemaBindings >'.

manager := WebServices.XMLObjectMarshalingManager on:
                (WebServices.BindingBuilder loadFrom: schema
readStream).
value := ValueHolder new setValue: (OrderedCollection with: 1@1 with:
1->'1' ).
value value add: ( Rectangle origin: 0@0 corner: 20@20).
element := manager marshal: value atNamespace: 'urn:point'.

doc := XMLParser new validate: false; parse: element printString
readStream.
result := manager unmarshal: doc root.


Tamara Kogan
Smalltalk development,
Cincom Systems

> -----Original Message-----
> From: [hidden email] [mailto:[hidden email]]
> Sent: Thursday, July 12, 2007 7:51 AM
> To: [hidden email]
> Subject: XML: unmarshalling heterogeneous collections
>
> Hi there,
>
> I am trying to define an XML to Object binding that not only allows to
> marshal a heterogeneous collection but also unmarshals it correctly.
>
> I am currently using VW 7.4 and must admit I didn't check with 7.5.
>
> My problem:
> I have a list of folder objects that can contain folders as well as
other
> objects. So every folder has to define a collection mapping for a list
of
> unknown objects.
>
> I have read about anyCollection on comp.lang.smalltalk, and it does
> marshal to xml quite nicely. It doesn't unmarshal though: all
Collections
> are empty.
>
> The same is also true for sequence_of containing an any-Mapping: The
> marshal'ed xml looks good but is not unmarshalled back to non-empty
> collections.
>
> Does anybody know a way how to map heterogeneous collections so that
both
> directions (objects->xml and xml->objects) work?
>
> Any help is appreciated
>
> thanx
>
> Joachim

Reply | Threaded
Open this post in threaded view
|

RE: unmarshalling heterogeneous collections

Kogan, Tamara
> I must admit I don't really understand why it is needed and makes such
a
> difference. Isn't an anyCollection a collection of whatever there
might
> come along, as long as there is a mapping available for it?
There are a few places in the x2o framework that we do need to revisit
and clean up.

 
> Is there any documentation available (blog posts, white papers or
> whatever) that could have helped me on this path?
Unfortunately the only available documentation now is the
WebServices.pdf

Tamara


>
> --- original message follows ---
>
>
> I hope the sample below helps.
>
>
> schema := '<schemaBindings >
> <xmlToSmalltalkBinding name="AnyCollection"
> xmlns:xsd="http://www.w3.org/2000/10/XMLSchema"
> targetNamespace="urn:point">
> <object name="point" smalltalkClass="Point">
>  <attribute name="x" ref="xsd:float"/>
>  <attribute name="y" ref="xsd:float"/>
> </object>
> <object name="rectangle" smalltalkClass="Rectangle">
>  <element name="origin" ref="point"/>
>  <element name="corner" ref="point"/>
> </object>
> <object name="association" smalltalkClass="Association">
>  <attribute name="key" ref="xsd:int"/>
>  <attribute name="value" ref="xsd:string"/>
> </object>
> <object name = "CollectionHolder" smalltalkClass="ValueHolder">
> <anyCollection name="value" setSelector="setValue:" xpath="child::*"/>
> </object>
> </xmlToSmalltalkBinding>
> </schemaBindings >'.
>
> manager := WebServices.XMLObjectMarshalingManager on:
> (WebServices.BindingBuilder loadFrom: schema
> readStream).
> value := ValueHolder new setValue: (OrderedCollection with: 1@1 with:
> 1->'1' ).
> value value add: ( Rectangle origin: 0@0 corner: 20@20).
> element := manager marshal: value atNamespace: 'urn:point'.
>
> doc := XMLParser new validate: false; parse: element printString
> readStream.
> result := manager unmarshal: doc root.
>
>
> Tamara Kogan
> Smalltalk development,
> Cincom Systems
>
> > -----Original Message-----
> > From: [hidden email] [mailto:[hidden email]]
> > Sent: Thursday, July 12, 2007 7:51 AM
> > To: [hidden email]
> > Subject: XML: unmarshalling heterogeneous collections
> >
> > Hi there,
> >
> > I am trying to define an XML to Object binding that not only allows
to
> > marshal a heterogeneous collection but also unmarshals it correctly.
> >
> > I am currently using VW 7.4 and must admit I didn't check with 7.5.
> >
> > My problem:
> > I have a list of folder objects that can contain folders as well as
> other
> > objects. So every folder has to define a collection mapping for a
list

> of
> > unknown objects.
> >
> > I have read about anyCollection on comp.lang.smalltalk, and it does
> > marshal to xml quite nicely. It doesn't unmarshal though: all
> Collections
> > are empty.
> >
> > The same is also true for sequence_of containing an any-Mapping: The
> > marshal'ed xml looks good but is not unmarshalled back to non-empty
> > collections.
> >
> > Does anybody know a way how to map heterogeneous collections so that
> both
> > directions (objects->xml and xml->objects) work?
> >
> > Any help is appreciated
> >
> > thanx
> >
> > Joachim