How-to create a simple Drupal XML node type

You want to use Flash or other dynamic elements in your Drupal site, you want these elements to reference dynamic XML (or minimally XML you can quickly change). You want a simple solution not overkill. You can code PHP and provide any of the data from your site but need to display an XML file.

Following are quick and dirty instructions to provide XML directly or generated by PHP in the body of a node. We do this by creating a new Content Type for XML, simplifying the templates, using PHP to create XML content and then the Path module to display the .xml extension to the node.

Call it what you will. Try This:

  • create a new content type named “xmltype”
  • override 2x .tpl.php pages (to just "print $content;")
    • page-node-4.tpl.php (needs to be done for each specific XML node)
    • node-xmltype.tpl.php
    • duplicate page.tpl.php to page-node-edit.tpl.php
  • enable Path module
    • name the node nodename.xml
  • use PHP input type to create XML dynamically or display specifically what XML you want

Comments

  • what about overriding the page.tpl per type, rather than per node?
  • what about accessing the RSS for one node directly using the built in RSS?

I had gone for much more elaborate solutions for Drupal XML before, thanks this makes perfect sense. Though a little more detail in the example would be nice for the laymen.

Could you give more details please???

Where are page-node-4.tpl.php??

Or, these notes are quick and dirty. :)
I assume you understand these are .tpl files for your theme. And the specific .tpl you asked about was for specifically node/4 in this example.

Add new comment