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.
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.