p:http-request to get file: URI

Hi all,

Just for the record in case it can help others, here's how to load a  
local XML file from a GET HTTP request on a file: URI:

First I tried with the following Pipeline:

<p:declare-step xmlns:p="http://www.w3.org/ns/xproc"
   xmlns:c="http://www.w3.org/ns/xproc-step" version="1.0"
   xmlns:z="http://www.daisy.org/ns/z3986/authoring/">

   <p:output port="result" sequence="true"/>

   <p:option name="href" select="'file:///Users/Romain/Documents/file.xml' 
"/>
   <p:option name="output" select="'output'"/>

   <p:add-attribute match="/c:request" attribute-name="href">
     <p:input port="source">
       <p:inline>
         <c:request method="get"  detailed="false"/>
       </p:inline>
     </p:input>
     <p:with-option name="attribute-value" select="$href"/>
   </p:add-attribute>

   <p:http-request media-type="application/xml"/>

<!--  <p:unescape-markup encoding="base64" charset="utf8"/>-->

</p:declare-step>

However I was returned a c:body encoded in base64.

Using   <p:unescape-markup encoding="base64" charset="utf8"/> didn't  
work since it choked on the xml prolog within the content of the c:body.

After a little search in the XProc spec, I found that the trick is to  
use the override-content-type="application/xml" attribute on the  
c:request, to inform the http-request step that I'm getting an XML  
document.

It may be simpler if Calabash would automatically detect XML documents  
and not encode them in base64, but I'm not sure if it can be easily  
implemented.

BR,
Romain.

PS: it's also possible to use the simpler p:load step, but in this  
specific case I needed to use the p:http-request.

Received on Thursday, 7 October 2010 09:32:24 UTC