PHP/Drupal code to generate CMS content as XML
- Trigger the alternative theme that writes XML
- Write the theme that renders XML
1)
In your page.tpl.php, add this code at the top
<?php
if (($_GET["format"])==("xml")) {
include 'xml.page.tpl.php'; /*call the alternative template file */
return; }
?>
Do the same for node.tpl.php and this time point to an alternative node.tpl.php
<?php
if (($_GET["format"])==("xml")) {
include 'xml.node.tpl.php'; /*call the alternative template file */
return; }
?>
Example xml.page.tpl.php and xml.node.tpl.php (the naming format is arbitrary and can be anything)
<?php
$xml_header='<?xml version="1.0" encoding="ISO-8859-1"?>';
header('Content-type: text/xml');
print $xml_header;
?>
<drupal_page>
<?php print $content; ?>
</drupal_page>
<node>
<link><?php print $node_url ?></link>
<title><?php print $title ?></title>
<content><?php print $content ?></content>
</node>
Please note that this code is just an example of greater things that you can accomplish by creatively theming CMS data. You call pull-in more fields, and even take the resultant XML and manipulate it using XSLT, or consume it into Adobe flash for presentation... If you come up with some creative application, please share them with th rest of us by commenting on this website, or on Drupal.org: Drupal to XML: By theme, Server-side manipulation


