Quick links: Content - sections - sub sections
EN FR

jResponseXML allows to send an XML response to the client-browser. Its alias is "xml".

To create a jResponseXML object, pass 'xml' as argument to getResponse() method in your controller's action.


$resp = $this->getResponse('xml');

The XML content can be generated from a template or "by hand". The XML should be correctly formated in any case, or the response will generate an error.

jResponseXml handles generation of the <?xml ?> tag so you don't have to set it in the content you give. If you really want to, just write:


  $resp->sendXMLHeader = false;

The mime type by default is text/xml. You can change it by calling addHttpHeader:


  $rep->addHttpHeader('Content-Type', 'application/xml');

Generation with a template

The $content property contains a jTpl object by default : it's up to you to set the template-selector in property $contentTpl.


  $resp->contentTpl = 'myModule~myxml';
  $resp->content->assign('foo','bla bla bla');

Without a template

It's possible to set the XML content as a string value in property $content.


  $rep->content = '<mydoc> <title>jelix</title> </mydoc>';

Using style-sheets

It's possible to attach CSS or XSLT style-sheets to the generated XML document using method addCSSStyleSheet() or addXSLStyleSheet().

Both expect the same first mandatory argument : the URL to the style-sheet. Both expect the same second optional argument : an associative array defining the pseudo-attributes for the generated processing instruction.


 $rep->addCSSStyleSheet('/my.css', array('title'=>'Excellent!!'));
 $rep->addXSLStyleSheet('/my.xsl');

Note: the style sheets can be stored into the www/ of the application, or in a module. See the documentation about HTML views to know how to retrieve the real URL of files.