XML to Smalltalk

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

XML to Smalltalk

Andres Fortier-2
Hi list,
          I've a domain model already built and now I need to
instantiate it from XML files. Since so far the model was small and
simple I've been reading the XML using the XML Parser. However, as the
model's complexity started to increase, I decided it was time to switch
to another approach. My current situation is this:

- I have my domain classes already implemented.

- I get the object's information from another system in XML format. The
XML are (so far) not complex. Most of them are like:

<component>
        <assigned-to-id>XYZ</assigned-to-id>
        <completed-date type="datetime"></completed-date>
        <component-id type="integer"></component-id>
        ...
</component>

- There is no DTD available for the XML files.

I've been reading the Web Service Developer's Guide, but I'm a bit
confused on how to start. I guess I have to somehow create a schema and
feed it to a marshaller, but I'm a bit lost. Could somebody give me a
complete example on how to convert an XML to an concrete object? (e.g.
supposing a trivial model, like a class Person with one i.v. 'name' and
an XML file that has the form <person><name>john</name></person> )

Thanks in advance,
Andrés
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: XML to Smalltalk

Kogan, Tamara
Hi Andrés,

It helps if you load XMLObjectBindingWizard parcel. Click on Tools-> XML to Object Binding or X2OWizard in 7.7.1.
The tool helps you to describe your domain classes types and creates XML to object mapping. The last page of the wizard shows how to marshal the domain objects in XML and unmarshal XML to objects.

I attached a small example that includes two classes and Customer class>>x2oBinding is XML to object mapping created by the tool.
To marshal the customer object:
schemaNS := 'urn:vwservices' .
binding := WebServices.XMLObjectBinding bindingAtNamespace: schemaNS.
manager := WebServices.XMLObjectMarshalingManager on: binding.
manager
        useInlineType: true;
        useReference: true.
object := Customer new
        name: ("String");
        address: (Address new);
        yourself.
xml := manager
        marshal: object
        atNamespace: schemaNS.
unmarshaledObject := manager
        unmarshal: xml printString readStream
        atNamespace: schemaNS.
The example is created in 7.7

Tamara Kogan
Smalltalk development,
Cincom Systems
 

> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of andres
> Sent: Wednesday, November 17, 2010 11:48 AM
> To: VWNC List
> Subject: [vwnc] XML to Smalltalk
>
> Hi list,
>           I've a domain model already built and now I need to
> instantiate it from XML files. Since so far the model was small and
> simple I've been reading the XML using the XML Parser.
> However, as the
> model's complexity started to increase, I decided it was time
> to switch
> to another approach. My current situation is this:
>
> - I have my domain classes already implemented.
>
> - I get the object's information from another system in XML
> format. The
> XML are (so far) not complex. Most of them are like:
>
> <component>
> <assigned-to-id>XYZ</assigned-to-id>
> <completed-date type="datetime"></completed-date>
> <component-id type="integer"></component-id>
> ...
> </component>
>
> - There is no DTD available for the XML files.
>
> I've been reading the Web Service Developer's Guide, but I'm a bit
> confused on how to start. I guess I have to somehow create a
> schema and
> feed it to a marshaller, but I'm a bit lost. Could somebody give me a
> complete example on how to convert an XML to an concrete
> object? (e.g.
> supposing a trivial model, like a class Person with one i.v.
> 'name' and
> an XML file that has the form <person><name>john</name></person> )
>
> Thanks in advance,
> Andrés
> _______________________________________________
> vwnc mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
>

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc

TestCustomer.zip (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: XML to Smalltalk

Andres Fortier-2
Hi Tamara, thank you very much for the quick response and examples. I'm
currently working with VW 7.6, I hope things still apply :)
I'll work through the examples and let you know.

Thanks again!
Andrés


Kogan, Tamara escribió:

> Hi Andrés,
>
> It helps if you load XMLObjectBindingWizard parcel. Click on Tools-> XML to Object Binding or X2OWizard in 7.7.1.
> The tool helps you to describe your domain classes types and creates XML to object mapping. The last page of the wizard shows how to marshal the domain objects in XML and unmarshal XML to objects.
>
> I attached a small example that includes two classes and Customer class>>x2oBinding is XML to object mapping created by the tool.
> To marshal the customer object:
> schemaNS := 'urn:vwservices' .
> binding := WebServices.XMLObjectBinding bindingAtNamespace: schemaNS.
> manager := WebServices.XMLObjectMarshalingManager on: binding.
> manager
> useInlineType: true;
> useReference: true.
> object := Customer new
> name: ("String");
> address: (Address new);
> yourself.
> xml := manager
> marshal: object
> atNamespace: schemaNS.
> unmarshaledObject := manager
> unmarshal: xml printString readStream
> atNamespace: schemaNS.
> The example is created in 7.7
>
> Tamara Kogan
> Smalltalk development,
> Cincom Systems
>  
>
>> -----Original Message-----
>> From: [hidden email]
>> [mailto:[hidden email]] On Behalf Of andres
>> Sent: Wednesday, November 17, 2010 11:48 AM
>> To: VWNC List
>> Subject: [vwnc] XML to Smalltalk
>>
>> Hi list,
>>           I've a domain model already built and now I need to
>> instantiate it from XML files. Since so far the model was small and
>> simple I've been reading the XML using the XML Parser.
>> However, as the
>> model's complexity started to increase, I decided it was time
>> to switch
>> to another approach. My current situation is this:
>>
>> - I have my domain classes already implemented.
>>
>> - I get the object's information from another system in XML
>> format. The
>> XML are (so far) not complex. Most of them are like:
>>
>> <component>
>> <assigned-to-id>XYZ</assigned-to-id>
>> <completed-date type="datetime"></completed-date>
>> <component-id type="integer"></component-id>
>> ...
>> </component>
>>
>> - There is no DTD available for the XML files.
>>
>> I've been reading the Web Service Developer's Guide, but I'm a bit
>> confused on how to start. I guess I have to somehow create a
>> schema and
>> feed it to a marshaller, but I'm a bit lost. Could somebody give me a
>> complete example on how to convert an XML to an concrete
>> object? (e.g.
>> supposing a trivial model, like a class Person with one i.v.
>> 'name' and
>> an XML file that has the form <person><name>john</name></person> )
>>
>> Thanks in advance,
>> Andrés
>> _______________________________________________
>> vwnc mailing list
>> [hidden email]
>> http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
>>
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: XML to Smalltalk

Andres Fortier-2
Ok, I kind of got it working, though I'm not sure it is the right way of
doing it :)

SimpleTest>>fromXML: anXML

                | schemaNS binding marshaler manager |

                schemaNS:='urn:vwservices' .
                binding:=WebServices.XMLObjectBinding bindingAtNamespace: schemaNS.
                marshaler:=binding marshalerForClass: SimpleTest ifAbsent: [self
error: 'There is no binding for this class'].
                manager:=WebServices.XMLObjectMarshalingManager on: binding.
                manager
                                useInlineType: true;
                                useReference: true.
                ^manager
                                unmarshal: anXML
                                with: marshaler.


And now I can do:

| xml stream |

stream:='<SimpleTest >
        <number>21</number>
        <summary>test</summary>
</SimpleTest>'  readStream.

xml:=((XMLParser on: stream)
                                                validate: false;
                                                scanDocument)
                                                root.
SimpleTest fromXML: xml.

Thanks again for your help,
Andrés

andres escribió:

> Hi Tamara, I've done some simple tests and things seem to work ok. I
> have just one doubt: The example xml generated by the marshaller is
> something like:
>
> <ns:SimpleTest xsi:type="ns:SimpleTest" xmlns:ns="urn:vwservices"
> xmlns:ns0="http://www.w3.org/2001/XMLSchema"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>     <ns:summary xsi:type="ns0:string">test</ns:summary>
>     <ns:number xsi:type="ns0:short">21</ns:number>
> </ns:SimpleTest>
>
> While the input I have to handle would look like:
>
> <simpleTest>
>     <summary>test</summary>
>     <number>21</number>
> </simpleTest>
>
> I've tried using that input for the unmarshaller and I get all sorts of
> errors, so I was wondering if it is possible to generate an unmarshaller
> that can process that kind of input or if I can configure the manager or
> the unmarshaller to fit that kind of xml document.
>
> Thank you very much for your time,
> Andrés
>
>
> andres escribió:
>> Hi Tamara, thank you very much for the quick response and examples.
>> I'm currently working with VW 7.6, I hope things still apply :)
>> I'll work through the examples and let you know.
>>
>> Thanks again!
>> Andrés
>>
>>
>> Kogan, Tamara escribió:
>>> Hi Andrés,
>>>
>>> It helps if you load XMLObjectBindingWizard parcel. Click on Tools->
>>> XML to Object Binding or X2OWizard in 7.7.1.
>>> The tool helps you to describe your domain classes types and creates
>>> XML to object mapping. The last page of the wizard shows how to
>>> marshal the domain objects in XML and unmarshal XML to objects.
>>>
>>> I attached a small example that includes two classes and Customer
>>> class>>x2oBinding is XML to object mapping created by the tool.
>>> To marshal the customer object:
>>> schemaNS := 'urn:vwservices' .
>>> binding := WebServices.XMLObjectBinding bindingAtNamespace: schemaNS.
>>> manager := WebServices.XMLObjectMarshalingManager on: binding.
>>> manager
>>>     useInlineType: true;
>>>     useReference: true.
>>> object := Customer new
>>>     name: ("String");
>>>     address: (Address new);
>>>     yourself.
>>> xml := manager
>>>     marshal: object
>>>     atNamespace: schemaNS.
>>> unmarshaledObject := manager
>>>     unmarshal: xml printString readStream
>>>     atNamespace: schemaNS.
>>> The example is created in 7.7
>>>
>>> Tamara Kogan Smalltalk development,
>>> Cincom Systems
>>>  
>>>
>>>> -----Original Message-----
>>>> From: [hidden email] [mailto:[hidden email]] On
>>>> Behalf Of andres
>>>> Sent: Wednesday, November 17, 2010 11:48 AM
>>>> To: VWNC List
>>>> Subject: [vwnc] XML to Smalltalk
>>>>
>>>> Hi list,
>>>>           I've a domain model already built and now I need to
>>>> instantiate it from XML files. Since so far the model was small and
>>>> simple I've been reading the XML using the XML Parser. However, as
>>>> the model's complexity started to increase, I decided it was time to
>>>> switch to another approach. My current situation is this:
>>>>
>>>> - I have my domain classes already implemented.
>>>>
>>>> - I get the object's information from another system in XML format.
>>>> The XML are (so far) not complex. Most of them are like:
>>>>
>>>> <component>
>>>>     <assigned-to-id>XYZ</assigned-to-id>
>>>>     <completed-date type="datetime"></completed-date>
>>>>     <component-id type="integer"></component-id>
>>>>     ...
>>>> </component>
>>>>
>>>> - There is no DTD available for the XML files.
>>>>
>>>> I've been reading the Web Service Developer's Guide, but I'm a bit
>>>> confused on how to start. I guess I have to somehow create a schema
>>>> and feed it to a marshaller, but I'm a bit lost. Could somebody give
>>>> me a complete example on how to convert an XML to an concrete
>>>> object? (e.g. supposing a trivial model, like a class Person with
>>>> one i.v. 'name' and an XML file that has the form
>>>> <person><name>john</name></person> )
>>>>
>>>> Thanks in advance,
>>>> Andrés
>>>> _______________________________________________
>>>> vwnc mailing list
>>>> [hidden email]
>>>> http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
>>>>
>> _______________________________________________
>> vwnc mailing list
>> [hidden email]
>> http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
>>
>
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: XML to Smalltalk

Kogan, Tamara
It is one of the ways :-)
Good luck!

Tamara Kogan
Smalltalk development,
Cincom Systems
 

> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of andres
> Sent: Wednesday, November 17, 2010 4:37 PM
> To: VWNC List
> Subject: Re: [vwnc] XML to Smalltalk
>
> Ok, I kind of got it working, though I'm not sure it is the
> right way of
> doing it :)
>
> SimpleTest>>fromXML: anXML
>
> | schemaNS binding marshaler manager |
>
> schemaNS:='urn:vwservices' .
> binding:=WebServices.XMLObjectBinding
> bindingAtNamespace: schemaNS.
> marshaler:=binding marshalerForClass:
> SimpleTest ifAbsent: [self
> error: 'There is no binding for this class'].
> manager:=WebServices.XMLObjectMarshalingManager
> on: binding.
> manager
> useInlineType: true;
> useReference: true.
> ^manager
> unmarshal: anXML
> with: marshaler.
>
>
> And now I can do:
>
> | xml stream |
>
> stream:='<SimpleTest >
> <number>21</number>
> <summary>test</summary>
> </SimpleTest>'  readStream.
>
> xml:=((XMLParser on: stream)
> validate: false;
> scanDocument)
> root.
> SimpleTest fromXML: xml.
>
> Thanks again for your help,
> Andrés
>
> andres escribió:
> > Hi Tamara, I've done some simple tests and things seem to
> work ok. I
> > have just one doubt: The example xml generated by the marshaller is
> > something like:
> >
> > <ns:SimpleTest xsi:type="ns:SimpleTest" xmlns:ns="urn:vwservices"
> > xmlns:ns0="http://www.w3.org/2001/XMLSchema"
> > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
> >     <ns:summary xsi:type="ns0:string">test</ns:summary>
> >     <ns:number xsi:type="ns0:short">21</ns:number>
> > </ns:SimpleTest>
> >
> > While the input I have to handle would look like:
> >
> > <simpleTest>
> >     <summary>test</summary>
> >     <number>21</number>
> > </simpleTest>
> >
> > I've tried using that input for the unmarshaller and I get
> all sorts of
> > errors, so I was wondering if it is possible to generate an
> unmarshaller
> > that can process that kind of input or if I can configure
> the manager or
> > the unmarshaller to fit that kind of xml document.
> >
> > Thank you very much for your time,
> > Andrés
> >
> >
> > andres escribió:
> >> Hi Tamara, thank you very much for the quick response and
> examples.
> >> I'm currently working with VW 7.6, I hope things still apply :)
> >> I'll work through the examples and let you know.
> >>
> >> Thanks again!
> >> Andrés
> >>
> >>
> >> Kogan, Tamara escribió:
> >>> Hi Andrés,
> >>>
> >>> It helps if you load XMLObjectBindingWizard parcel. Click
> on Tools->
> >>> XML to Object Binding or X2OWizard in 7.7.1.
> >>> The tool helps you to describe your domain classes types
> and creates
> >>> XML to object mapping. The last page of the wizard shows how to
> >>> marshal the domain objects in XML and unmarshal XML to objects.
> >>>
> >>> I attached a small example that includes two classes and Customer
> >>> class>>x2oBinding is XML to object mapping created by the tool.
> >>> To marshal the customer object:
> >>> schemaNS := 'urn:vwservices' .
> >>> binding := WebServices.XMLObjectBinding
> bindingAtNamespace: schemaNS.
> >>> manager := WebServices.XMLObjectMarshalingManager on: binding.
> >>> manager
> >>>     useInlineType: true;
> >>>     useReference: true.
> >>> object := Customer new
> >>>     name: ("String");
> >>>     address: (Address new);
> >>>     yourself.
> >>> xml := manager
> >>>     marshal: object
> >>>     atNamespace: schemaNS.
> >>> unmarshaledObject := manager
> >>>     unmarshal: xml printString readStream
> >>>     atNamespace: schemaNS.
> >>> The example is created in 7.7
> >>>
> >>> Tamara Kogan Smalltalk development,
> >>> Cincom Systems
> >>>  
> >>>
> >>>> -----Original Message-----
> >>>> From: [hidden email]
> [mailto:[hidden email]] On
> >>>> Behalf Of andres
> >>>> Sent: Wednesday, November 17, 2010 11:48 AM
> >>>> To: VWNC List
> >>>> Subject: [vwnc] XML to Smalltalk
> >>>>
> >>>> Hi list,
> >>>>           I've a domain model already built and now I need to
> >>>> instantiate it from XML files. Since so far the model
> was small and
> >>>> simple I've been reading the XML using the XML Parser.
> However, as
> >>>> the model's complexity started to increase, I decided it
> was time to
> >>>> switch to another approach. My current situation is this:
> >>>>
> >>>> - I have my domain classes already implemented.
> >>>>
> >>>> - I get the object's information from another system in
> XML format.
> >>>> The XML are (so far) not complex. Most of them are like:
> >>>>
> >>>> <component>
> >>>>     <assigned-to-id>XYZ</assigned-to-id>
> >>>>     <completed-date type="datetime"></completed-date>
> >>>>     <component-id type="integer"></component-id>
> >>>>     ...
> >>>> </component>
> >>>>
> >>>> - There is no DTD available for the XML files.
> >>>>
> >>>> I've been reading the Web Service Developer's Guide, but
> I'm a bit
> >>>> confused on how to start. I guess I have to somehow
> create a schema
> >>>> and feed it to a marshaller, but I'm a bit lost. Could
> somebody give
> >>>> me a complete example on how to convert an XML to an concrete
> >>>> object? (e.g. supposing a trivial model, like a class
> Person with
> >>>> one i.v. 'name' and an XML file that has the form
> >>>> <person><name>john</name></person> )
> >>>>
> >>>> Thanks in advance,
> >>>> Andrés
> >>>> _______________________________________________
> >>>> vwnc mailing list
> >>>> [hidden email]
> >>>> http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
> >>>>
> >> _______________________________________________
> >> vwnc mailing list
> >> [hidden email]
> >> http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
> >>
> >
> _______________________________________________
> vwnc mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
>

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc