XML unmarshalling - key and keyRef

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

XML unmarshalling - key and keyRef

Steffen Märcker
Hi,

I'd like to unmarshal a given document which uses references to arbitrary  
elements via an unique attribute. Example:

<root>
        <a no="1"/>
        <b no="2"/>
        <c no="3" refTo="1"/>
        <c no="4" refTo="2"/>
        <c no="5" refTo="3"/>
</root>

Unfortunately I couldn't figure out a working binding specification. My  
last attempt used an artificial general type <object name="xxx"... and  
derived <object name="a" baseType="xxx"... and the other objects from  
this. That general defined the key "no". However, the references haven't  
been resolved at all.

Any ideas?

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

Re: XML unmarshalling - key and keyRef

Holger Kleinsorgen-4
Hi,

given two classes, ArbitraryList (with instVar accessors #elements) and
ArbitraryElement (with accessors #number and #referencedElement), the
following XML binding will unmarshal the arbitrary elements including
the references:

<xmlToSmalltalkBinding name="ArbitrayList"
   xmlns:xsd="http://www.w3.org/2001/XMLSchema"
 >

<object name="root" smalltalkClass="ArbitraryList">
   <element aspect="elements" xpath="*" ref="arbitraryElement"
minOccurs="0" maxOccurs="*"/>
</object>

<object name="arbitraryElement" smalltalkClass="ArbitraryElement">
   <key name="elementKey">
     <attribute aspect="number" name="no" ref="xsd:integer"/>
   </key>
   <attribute aspect="number" name="no" ref="xsd:integer"/>
   <attribute aspect="referencedElement" name="refTo"
ref="arbitraryElement" minOccurs="0">
     <keyRef ref="elementKey" >
       <attribute name="refTo" ref="xsd:integer"/>
     </keyRef>
   </attribute>
</object>

</xmlToSmalltalkBinding>


> I'd like to unmarshal a given document which uses references to arbitrary
> elements via an unique attribute. Example:
>
> <root>
> <a no="1"/>
> <b no="2"/>
> <c no="3" refTo="1"/>
> <c no="4" refTo="2"/>
> <c no="5" refTo="3"/>
> </root>
>
> Unfortunately I couldn't figure out a working binding specification. My
> last attempt used an artificial general type<object name="xxx"... and
> derived<object name="a" baseType="xxx"... and the other objects from
> this. That general defined the key "no". However, the references haven't
> been resolved at all.
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: XML unmarshalling - key and keyRef

Steffen Märcker
Thanks,

looks good so far but in this example the elements <a>, <b>, <c> are all  
unmarshalled to the class ArbitraryElement. In my case I need to unmarshal  
them to 3 different classes, say ClassA, ClassB and ClassC. Is there a way  
to achieve this?
To talk more general, I have an XML where almost each element has an  
unique attribute, say 'no'. Certain elements may reference arbitrary  
elements via an attribute, say 'refTo' and it's possible that element <a>  
references at one position <b> and at another element <c>. But <a>, <b>  
and <c> need to be unmarshalled to different classes.

Regard,
Steffen


Am 21.10.2010, 14:27 Uhr, schrieb Holger Kleinsorgen  
<[hidden email]>:

> Hi,
>
> given two classes, ArbitraryList (with instVar accessors #elements) and
> ArbitraryElement (with accessors #number and #referencedElement), the
> following XML binding will unmarshal the arbitrary elements including
> the references:
>
> <xmlToSmalltalkBinding name="ArbitrayList"
>    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>  >
>
> <object name="root" smalltalkClass="ArbitraryList">
>    <element aspect="elements" xpath="*" ref="arbitraryElement"
> minOccurs="0" maxOccurs="*"/>
> </object>
>
> <object name="arbitraryElement" smalltalkClass="ArbitraryElement">
>    <key name="elementKey">
>      <attribute aspect="number" name="no" ref="xsd:integer"/>
>    </key>
>    <attribute aspect="number" name="no" ref="xsd:integer"/>
>    <attribute aspect="referencedElement" name="refTo"
> ref="arbitraryElement" minOccurs="0">
>      <keyRef ref="elementKey" >
>        <attribute name="refTo" ref="xsd:integer"/>
>      </keyRef>
>    </attribute>
> </object>
>
> </xmlToSmalltalkBinding>
>
>
>> I'd like to unmarshal a given document which uses references to  
>> arbitrary
>> elements via an unique attribute. Example:
>>
>> <root>
>> <a no="1"/>
>> <b no="2"/>
>> <c no="3" refTo="1"/>
>> <c no="4" refTo="2"/>
>> <c no="5" refTo="3"/>
>> </root>
>>
>> Unfortunately I couldn't figure out a working binding specification. My
>> last attempt used an artificial general type<object name="xxx"... and
>> derived<object name="a" baseType="xxx"... and the other objects from
>> this. That general defined the key "no". However, the references haven't
>> been resolved at all.
> _______________________________________________
> 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 unmarshalling - key and keyRef

Holger Kleinsorgen-4
Hi Stefen,

ah I missed the point :/ Here's my hack-ish solution:

1. Hack: add a new method

   ComplexObjectMarshaler>>copyFromSuper: anotherMarshaler

      super copyFromSuper: anotherMarshaler .
      keyRefMarshaler ifNil: [keyRefMarshaler := anotherMarshaler
keyRefMarshaler].
      keyMarshalers ifNil: [keyMarshalers := anotherMarshaler
keyMarshalers].


when setting baseType, the key/ref marshalers are not copied from the
base type. this hack "solves" this problem. IMHO it's a valid fix, but
there might be other situations where this can cause problems.

2. define an XML binding like this

   <object name="root" smalltalkClass="ArbitraryList">
     <anyCollection aspect="elements" allowDerivedTypes="true"/>
   </object>

   <object name="arbitraryElement" smalltalkClass="ArbitraryElement">
     <key name="elementKey">
       <attribute aspect="number" name="no" ref="xsd:integer"/>
     </key>
     <attribute aspect="referencedElement" name="refTo"
ref="arbitraryElement" minOccurs="0" allowDerivedTypes="true">
       <keyRef ref="elementKey" >
         <attribute name="refTo" ref="xsd:integer"/>
       </keyRef>
     </attribute>
     <attribute aspect="number" name="no" ref="xsd:integer"/>
   </object>

   <object name="a" smalltalkClass="ElementA" baseType="arbitraryElement"/>
   <object name="b" smalltalkClass="ElementB" baseType="arbitraryElement"/>
    <object name="c" smalltalkClass="ElementC" baseType="arbitraryElement"/>


>
> looks good so far but in this example the elements<a>,<b>,<c>  are all
> unmarshalled to the class ArbitraryElement. In my case I need to unmarshal
> them to 3 different classes, say ClassA, ClassB and ClassC. Is there a way
> to achieve this?
> To talk more general, I have an XML where almost each element has an
> unique attribute, say 'no'. Certain elements may reference arbitrary
> elements via an attribute, say 'refTo' and it's possible that element<a>
> references at one position<b>  and at another element<c>. But<a>,<b>
> and<c>  need to be unmarshalled to different classes.
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc