Logo         Community
The Company
Your Account
Contact Us
Injecting XML Content Into Page Templates With patXMLRenderer (part 2)
Cache content, log activities and report usage with patXMLRenderer

| Serving It Up |

Why stop there? One of the cooler new features in patXMLRenderer is the ability to dynamically calculate attribute values at run-time, and insert them into your template. To illustrate this, consider the following XML files, which uses variables instead of static values in the attributes:

<?xml version="1.0"?>
<server name="$name" root="$root" type="$type" />

Here's the template corresponding to this XML file,

<!-- main page -->
<patTemplate:tmpl name="server">
This server is running {TYPE}. Server document root is {ROOT} and server name is {NAME}.

and here's the PHP script which dynamically obtains the server information and assigns it to the variables in the XML file:


// include config file
require_once( "config/patXMLRenderer.php" );

// include patTemplate class
require_once( "include/patTemplate.php" );

// include patXMLRenderer clas
require_once( "include/patXMLRenderer.php" );

// initialize XML rendering class
$randy = new patXMLRenderer;

// set base directory for XML content

// set XML file to use

// initialize template engine
$template = new patTemplate();

// set base directory for templates

// connect template object to renderer object

// set template file to use

// set list of skins

// set up renderer

// set dynamic attribute values
$randy->setParam("name", $_SERVER['SERVER_NAME']);
$randy->setParam("root", $_SERVER['DOCUMENT_ROOT']);
$randy->setParam("type", $_SERVER['SERVER_SOFTWARE']);

// parse XML file
// interpolate variables
// display output

And here's what the output looks like:

''.preg_replace(array('/  /', '/ /'), array('  ', '   '), '
This server is running Apache/1.3.11 (Win32) PHP/4.2.0. Server document root is c:/program files/internet tools/apache/htdocs and server name is medusa.gorgon.com.

Here, the call to setParam() assigns a value - which may be calculated dynamically by PHP - to the variables in the XML file prior to having that XML content transformed into HTML. This capability makes it possible to create portable XML files, wherein some data fragments are generated dynamically, every time the script runs. If you were to move the files above to a new server, for example, the output would automatically update itself with the new server details.

How to do Everything with PHP & MySQL
How to do Everything with PHP & MySQL, the best-selling book by Melonfire, explains how to take full advantage of PHP's built-in support for MySQL and link the results of database queries to Web pages. You'll get full details on PHP programming and MySQL database development, and then you'll learn to use these two cutting-edge technologies together. Easy-to-follow sample applications include a PHP online shopping cart, a MySQL order tracking system, and a PHP/MySQL news publishing system.

Read more, or grab your copy now!

previous page more like this  print this article  next page
In trog...
Logging With PHP
Building A Quick-And-Dirty PHP/MySQL Publishing System
Output Buffering With PHP
Date/Time Processing With PHP
Creating Web Calendars With The PEAR Calendar Class
In the hitg report...
Crime Scenes
Animal Attraction
Lord Of The Strings
In boombox...
Patience - George Michael
Think Tank - Blur
My Private Nation - Train
In colophon...
Hostage - Robert Crais
The Dead Heart - Douglas Kennedy
Right As Rain - George Pelecanos
In cut!...
American Chai
The Core
Find out how you can use this article on your own Web site!

Copyright © 1998-2018 Melonfire. All rights reserved
Terms and Conditions | Feedback