XML output from CMSBuilder

3 posts by 3 authors in: Forums > CMS Builder
Last Post: August 30, 2011   (RSS)

By Andrea11 - August 30, 2011 - edited: August 30, 2011

Re: [Andrea11] XML output from CMSBuilder

By gkornbluth - August 30, 2011

Hi Andrea,

Is the example code the output that you're trying to create on your page?

If so, it should be pretty easy.

Set up a multi-record table (call it my_songs) with at least 3 fields. Text fields for title and creator, and an upload field for location that's limited to one upload and mp3 files.

Create a few records for testing purposes

Then for your viewer (web page) code at the top of the page: (take this from the code generator, the code below has no path to your CMSB files and won't work)
?php header('Content-type: text/html; charset=utf-8'); ?>
<?php


// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('/path_to_your_cmsb_files/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

// load records
list($my_songsRecords, $my_songsMetaData) = getRecords(array(
'tableName' => 'my_songs',
));

?>


And in the body to produce the example you showed:

<?PHP echo "<?xml version='1.0' encoding='UTF-8'?>\n"; ?>
<playlist version="1" xmlns="http://xspf.org/ns/0/">
<trackList>
<?php foreach ($my_songsRecords as $record): ?>
<track>
<title><?php echo $record['title'] ?></title>
<creator><?php echo $record['creator'] ?></creator>
<location><?php foreach ($record['location'] as $upload): ?><?php echo $upload['urlPath'] ?><?php endforeach ?></location>
</track>
<?php endforeach ?>
</trackList>
</playlist>


I didn't have time to test it out, but is should work or get you close.

Good luck,

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php