Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

SOAP-Lite Empty Strings

by JamesBrown (Initiate)
on May 03, 2012 at 22:49 UTC ( #968828=perlquestion: print w/replies, xml ) Need Help??
JamesBrown has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks, I'm using SOAP::Lite and am trying to generate this XML string for Cisco Call Manager's AXL service:
<destination xsi:type="xsd:string"></destination>
The intention is to send an empty string in order to remove a Call Forward setting. Unfortunately, a debug reveals that SOAP::Lite uses the abbreviated notation and Cisco doesn't seem to like it:
<destination xsi:type="xsd:string" />
My code is as follows:
$oResult = $oCM->updateLine( SOAP::Data->name('destination' => '') );
Could anyone advise me on how to force SOAP::Lite to generate the longer notation please? Many thanks James.

Replies are listed 'Best First'.
Re: SOAP-Lite Empty Strings
by Anonymous Monk on May 04, 2012 at 09:05 UTC

    See Re: Suppressing nil attribute in empty SOAP tag and Re: I do not understand how to write a SOAP server. and switch away from SOAP::Lite :) because this is eew

    #!/usr/bin/perl -- use strict; use warnings; use SOAP::Lite; my $param = SOAP::Data->type("xsd:string")->name( "EmptyEmptorIsEmpty" )->value( '' ); ## track down sub tag #~ use Devel::TraceCalls { Package => 'SOAP::Serializer' }; #~ SOAP::Serializer->envelope( method => 'DoThis', $param ); exit; my $soap = SOAP::Lite ->proxy( 'http://localhost/blah/DummyService', timeout => 0.00001, ); $soap->transport->add_handler("request_send", \&pp_dump ); $soap->serializer( MySerializer->new ); print pp( $soap->serializer()->envelope( method => 'DoThis', $param ), ), "\n\n"; $soap->call( 'DoThis', $param ); sub pp { use XML::Twig; open my($fh), '>', \my $str; no warnings 'newline'; XML::Twig->new( qw! pretty_print record ! )->parse( @_ )->print( $fh ); return $str; } sub pp_dump { { my $content = $_[0]->content(''); $_[0]->content( pp($content) ); } print $_[0]->as_string,"\n"; return; } BEGIN { package MySerializer; @MySerializer::ISA = 'SOAP::Serializer'; BEGIN { $INC{''} = __FILE__; } my $closer = 'EmptyEmptorIsEmpty'; sub tag { my $self = shift; my $tag = shift; my $ret = $self->SUPER::tag( $tag, @_ ); if( $tag eq $closer and not $ret =~ m{</\Q$closer\E>$} ){ chop $ret; chop $ret; return "$ret></$closer>"; } return $ret; } 1; } __END__ POST http://localhost/blah/DummyService HTTP/1.1 Accept: text/xml Accept: multipart/* Accept: application/soap User-Agent: SOAP::Lite/Perl/0.714 Content-Length: 448 Content-Type: text/xml; charset=utf-8 SOAPAction: "#DoThis" <?xml version="1.0" encoding="UTF-8"?> <soap:Envelope soap:encodingStyle=" +oding/" xmlns:soap="" xmlns: +soapenc="" xmlns:xsd="http:/ +/" xmlns:xsi=" +ma-instance"> <soap:Body> <DoThis> <EmptyEmptorIsEmpty xsi:type="xsd:string"> </EmptyEmptorIsEmpty> </DoThis> </soap:Body> </soap:Envelope>
Re: SOAP-Lite Empty Strings
by Khen1950fx (Canon) on May 04, 2012 at 00:35 UTC
    I've never tried it before; however, this is untested, but I'm guessing that you'll need to use document/literal:
    #!/usr/bin/perl use strict; use warnings; use SOAP::Lite; my $oCM = SOAP::Lite->service($url); $oCM = SOAP::Data->encodingStyle(''), my $oResult = $oCM->updateLine( SOAP::Data->name(destination => $url) );