Long before Amazon built SOAP interfaces to their product catalog, they had a REST interface. REST vs. SOAP aside, I really wanted a SOAP interface. So I used SOAP::Lite to marshall SOAP requests to and from the REST service. All I was essentially doing was taking a SOAP request, and composing a URL to scrape, scraping it, and then placing the raw XML I scraped into a SOAP response.
FYI: Full source of service available here.
When it came time to tackle the packaging of the raw XML I was at first concerned that I would have to instantiate a parser, or rebuilt the XML document in some way. Luckily, Paul (the creator of SOAP::Lite) set me straight.
To package raw XML in a SOAP::Data element, simply:
my $xml_content = fetch($url);
$xml_content =~ s/\<\?xml.*\?\>\n?//; # strip the <?xml blah?>
$xml_content =~ s/\<\!.*\>\n?//; # strip
return SOAP::Data->type('xml' => $xml_content);
In the above case I was dealing with a complete document, so I had to first strip the parts of the xml document I didn't need. Once that was done, just set the type to 'xml' and the value to your document... SOAP::Lite will do the rest.
Thanks, this helped alot.
Posted by: Boris Reitman | October 01, 2007 at 01:18 PM
I'm looking for a method to send a RAW XML request to a SOAP server with SOAP::Lite.
I have the whole XML request in the variable $rawxml. No modification is needed.
How can I send this $rawxml request to the server?
Posted by: Károly Sipos | September 22, 2008 at 08:08 AM