Monday, March 31, 2008

HTTP extension for Saxon

I have just finished a little extension function for Saxon, to be able to send HTTP request from XSLT 2.0 (and get the result back). The idea is based on the SOAP extension from Andrew Welch, but is less restricted, as it can perform other HTTP requests (besides SOAP request over HTTP.)

The function take two parameters: a URI and an element that describe the request (the payload, the headers, the HTTP method, etc.) The later looks like:

<http-request method="post" mime-type="text/xml" charset="utf-8">
   <header name="Header-Name">...</header>
   <header name="Header2-Name">...</header>
   <body>
      The textual value of body will be the payload of the HTTP request...
   </body>
</http-request>

Let's say such an element is bound to the variable $request, then you can call ex:http-send($request, 'http://...'), and you will get a result that will look like:

<http-response code="200">
   <message>OK</message>
   <header name="Header-Name">...</header>
   <header name="Header-x-Name">...</header>
   <body>
      The textual value of body was the payload of the HTTP response...
   </body>
</http-response>

All the info, javadoc, JAR file, sample, can be found at http://www.fgeorges.org/xslt/saxon-ext/. This page contains a full sample sending a SOAP message to a Web service and formating the result to a simple text.

Labels: , ,