PHP/Drupal code to generate CMS content as XML

There are two steps to the process:
- 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; }
?>

In my case, I am looking to see if there is a querystring format=xml as a condition

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; }
?>

2) The template files:
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>

and

<node>
<link><?php print $node_url ?></link>
<title><?php print $title ?></title>
<content><?php print $content ?></content>
</node>

There you go, test the code and correct any coding errors and it should work (I assume that you have already tested the implementation on cmsproducer.com). If you need help with this, please ask.

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

Valid XHTML 1.0 Strict
This site is accepts Oped ID authentication for login
This Website is Built Using Semantic Markup and Cascading Style Sheets (CSS)
Some usage rights are reserved, please contact us for approval before using it