#18 Support xsi:type attribute for derived types

open
nobody
None
5
2007-10-07
2007-10-07
Anonymous
No

Support the xsi:type attribute for identifying derived types

Discussion

  • Martin Kutter
    Martin Kutter
    2008-06-17

    Logged In: YES
    user_id=884175
    Originator: NO

    This requires the following changes:
    1. remove Typemaps (the Typemap branch already does this)
    2. place the prefixes used in the generator run into the interface classes and pass them down to the XML parser:
    3. factor out the XML Name to Perl Name conversion into some util module
    4. Make the parser use the class with the appropriate perl name for the xsi:type="foo" attribute.

    Actually, this is not that complicated, and would allow to do stuff possibly out of bounds of other XML processors: Derived types may even extend their parents...

     
  • DeCosta
    DeCosta
    2008-09-15

    While certainly not a perfect solution, I was able to make some progress by tweaking extension.tt and anyType.pm:

    diff ~/tmp/SOAP-WSDL-2.00.05/lib/SOAP/WSDL/Generator/Template/XSD/complexType/extension.tt lib/SOAP/WSDL/Generator/Template/XSD/complexType/extension.tt 70c70,73
    < %]
    \ No newline at end of file
    ---
    > %]
    > sub get_xsi_type {
    > return '[% complexType.get_name() %]';
    > }

    diff ~/tmp/SOAP-WSDL-2.00.05/lib/SOAP/WSDL/XSD/Typelib/Builtin/anyType.pm lib/SOAP/WSDL/XSD/Typelib/Builtin/anyType.pm
    23c23,25
    < return join q{} , "<$_[1]->{ name }" , $_[0]->serialize_attr() , q{ xsi:nil="true"/>}
    ---
    > return join q{} , "<$_[1]->{ name }" ,
    > $_[0]->get_xsi_type() ? qw{ xsi:type="$_[0]->get_xsi_type()"'} : q{},
    > $_[0]->serialize_attr() , q{ xsi:nil="true"/>}
    25,27d26
    < # return "empty" start tag if it's empty
    < return join q{}, "<$_[1]->{ name }" , $_[0]->serialize_attr() , '/>'
    < if ($_[1]->{ empty });
    29c28,32
    < return join q{}, "<$_[1]->{ name }" , $_[0]->serialize_attr() , '>';
    ---
    > return join q{},
    > "<$_[1]->{ name }" ,
    > $_[0]->get_xsi_type() ? qw{ xsi:type="$_[0]->get_xsi_type()"'} : q{},
    > $_[0]->serialize_attr() ,
    > $_[1]->{ empty } ? '/>' : '>'; # return empty tag if empty
    56a60,63
    > sub get_xsi_type {
    > return q{};
    > }
    >

    It may not be pretty, but now elements of extended types emit the xsi:type attribute; if I could get this fix (or something better) and a fix for 2023797 in an official 2.00.06 release or some such, I'd be one happy camper.

     
  • DeCosta
    DeCosta
    2008-09-16

    So, I didn't get that quite right (must've saved and not re-run my test):

    diff ~/tmp/SOAP-WSDL-2.00.05/lib/SOAP/WSDL/XSD/Typelib/Builtin/anyType.pm lib/SOAP/WSDL/XSD/Typelib/Builtin/anyType.pm
    23c23,25
    < return join q{} , "<$_[1]->{ name }" , $_[0]->serialize_attr() , q{ xsi:nil="true"/>}
    ---
    > return join q{} , "<$_[1]->{ name }" ,
    > $_[0]->get_xsi_type() ? q{ xsi:type="} . $_[0]->get_xsi_type() . q{"} : q{},
    > $_[0]->serialize_attr() , q{ xsi:nil="true"/>}
    25,27d26
    < # return "empty" start tag if it's empty
    < return join q{}, "<$_[1]->{ name }" , $_[0]->serialize_attr() , '/>'
    < if ($_[1]->{ empty });
    29c28,32
    < return join q{}, "<$_[1]->{ name }" , $_[0]->serialize_attr() , '>';
    ---
    > return join q{},
    > "<$_[1]->{ name }" ,
    > $_[0]->get_xsi_type() ? q{ xsi:type="} . $_[0]->get_xsi_type() . q{"} : q{},
    > $_[0]->serialize_attr() ,
    > $_[1]->{ empty } ? '/>' : '>'; # return empty tag if empty
    56a60,63
    > sub get_xsi_type {
    > return q{};
    > }
    >