Quick links: Content - sections - sub sections
EN FR

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

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


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

Two solutions exist to set the XML contents.

  • *Warning** : the XML should be correctly formated in any case, or the response will generate an error.

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');

jResponseXml handles generation of the "<?xml ?>" tag : it shouldn't be in the template-file.

If you don't want that jReponseXml generates the xml tag, set the sendXMLHeader to false :


  $resp->sendXMLHeader = false;

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>';

jResponseXml handles generation of the "<?xml ?>" tag : you shouldn't set it explicitely.

If you don't want that jReponseXml generates the xml tag, set the sendXMLHeader to false :


  $resp->sendXMLHeader = false;

Using style-sheets

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

Both expects the same first mandatory argument : the URL to the style-sheet. Both expects the same second optionnal argument : an associative array defining the pseudo-attributes for the generated procesing instruction. uction générée.


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