Generating XML using CMS

15 posts by 3 authors in: Forums > CMS Builder
Last Post: December 27, 2008   (RSS)

By meg - November 20, 2008

I have a website that contains flash XML components (a text box and image gallery). I did some brief reading through your forum and is it true that you have to convert the XML to a PHP document or is there a way to add a script to the XML document so I don't have to change the file extension?

Either way, is there a different type of code that I should use to accomplish this?
Please advise.
Thanks!

Re: [meg] Generating XML using CMS

By Dave - November 20, 2008

Hi Meg,

There is ways to make .xml files run as PHP and still output XML content. But for most part applications don't care what the file extension is, they care what the "Content-type" header you send is.

It doesn't show in your browser, but anytime you request a file or image from the server it sends a line that says what kind of content it's sending.

For XML files, add this to the top of your script:
<?php header('Content-type: application/xml; charset=utf-8'); ?>

And you can name your script with .xml.php so it runs as a php app but the .xml. makes it easy to remember that it actually outputs xml.

For an example see our doc page on creating an XML RSS feed with CMS Builder:
http://www.interactivetools.com/docs/cmsbuilder/rss_feeds.html

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Generating XML using CMS

By meg - December 5, 2008

Thanks Dave. I'm looking to connect the CMS to an XML file which connects to a Flash Gallery. Is there a way to use your photo gallery portion of the CMS to connect to this XML file?

The functions I need for this gallery CMS section:
-Upload control panel
-Information for the XML file: URL of the image, Caption (text box)
-Ideally, I would love to set parameters on file size and pixel width (as your CMS gallery offers)

XML sample:
<image>
<url>image_file_name.jpg</url>
<caption>Photo Caption Goes Here</caption>
</image>

What's the best way to achieve this? Is there a fairly simple solution?
Thanks so much!

Meg

Re: [Dave] Generating XML using CMS

Hi Dave,

I am doing the same thing here. I have made my viewer identical to the xml file. 2 Things I'm struggling with:

1. In the viewer ("events.php"), I get an error when using the declaration:
<?xml version="1.0" encoding="utf-8"?>

I presume this is because of punctuation in there? I have tried:

<?php echo('<?xml version="1.0" encoding="utf-8"?>'); ?>

But still no luck. Any idea what that should be?

2. In my flash file, I presume I should change all reference to "events.xml" to "events.php" correct? Or should my viewer have its name changed to a .xml file? Is that allowed?

Thanks.

Re: [benedict] Generating XML using CMS

By Dave - December 9, 2008

Hi Benedict,

Some php installs think anything in <? ?> tags is PHP code, including <?xml version="1.0" encoding="utf-8"?>

There's a few tricks to show it including yours:
<?php echo('<?xml version="1.0" encoding="utf-8"?>'); ?>

Or this one:
<<?php ?>?xml version="1.0" encoding="utf-8"?>

And yes, you should have your flash file call events.php (or name it events.xml.php to make it even more clear). It won't care about the file extension, just the content header that is sent. You can send an xml header like this. Just put this code at the top:

<?php header('Content-type: application/xml; charset=utf-8'); ?>

Hope that helps, let me know if you have any more questions. If you're still getting an error let me know what it is or post a link.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Generating XML using CMS

Still not working in 2 different projects I am working on (one an XML flash calendar, the other using Autofeeder Pro from Flashloaded.com). This is in spite of the fact that if you visit the xml page I am generating with my PHP (http://esvc000159.wic032u.server-web.com/slideshow.php) it is appearing perfectly.

I have sent 'Loaded a note and will keep you posted.

FYI, here is the viewer code I am using to create the above:

<?php header('Content-type: application/xml; charset=utf-8'); ?>
<?php require_once "e:/inetpub/esvc000159/cmsAdmin/lib/viewer_functions.php";

list($home_pageRecords, $home_pageMetaData) = getRecords(array(
'tableName' => 'home_page',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$home_pageRecord = @$home_pageRecords[0]; // get first record

?>
<slideshow randomDisplay='false'>
<?php foreach ($home_pageRecord['banner'] as $upload): ?>

<image src='<?php echo $upload['urlPath'] ?>' link='<?php echo $upload['info1'] ?>' inEffect='Fade in' outEffect='Fade out'>
<caption>No caption</caption>
</image>

<?php endforeach ?>
</slideshow>

Re: [benedict] Generating XML using CMS

By Dave - December 11, 2008

Hi benedict,

It looks like valid XML to me. I ran it through a few validators as well. What do the flash components do when you tell them to use it? Does it work when you save the output from slideshow.php as slideshow.php.xml and direct them to that?

Let me know what happens.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Generating XML using CMS

Interstingly if I change the links to be absolute (by adding the http:// + url in the section editor that creates the XML) then in Flash, when I publish the file, it works locally. But again, when I upload it, it does not work. That tells me that the actual XML is correct, but its delivery is not.

I then found one thing which may be an issue in the logs in Safari when it loads the page -

http://esvc000159.wic032u.server-web.com/slideshow.php?noCache=1229302787177

Not sure why it is adding this code to the end of slideshow.php, but when I follow that URL, it states:

Warning: Invalid argument supplied for foreach() in e:\inetpub\esvc000159\slideshow.php on line 15.

Here is my code again in slideshow.php:

<?php header('Content-type: application/xml; charset=utf-8'); ?>
<?php

require_once "e:/inetpub/esvc000159/cmsAdmin/lib/viewer_functions.php";

list($home_pageRecords, $home_pageMetaData) = getRecords(array(
'tableName' => 'home_page',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$home_pageRecord = @$home_pageRecords[0]; // get first record

?>
<slideshow randomDisplay='false'>
<?php foreach ($home_pageRecord['banner'] as $upload): ?>

<image src='http://esvc000159.wic032u.server-web.com<?php echo $upload['urlPath'] ?>' link='<?php echo $upload['info1'] ?>' inEffect='Fade in' outEffect='Fade out'>
<caption>No caption</caption>
</image>

<?php endforeach ?>
</slideshow>

Does this shed any light on the matter?

Re: [benedict] Generating XML using CMS

By Dave - December 15, 2008

Hi Benedict,

The way that viewer is coded it will load the record number from the end of the url. So if the server is adding "noCache=1229302787177" on the end it will try to load record 1229302787177 which won't exist.

Make sure when you load the XML file you pass the record number you want to load with something like:

.../slideshow.php?<?php echo $record['num'] ?>

Or if there is only one record in the section you can _remove_ this line so it just loads the first record:

'where' => whereRecordNumberInUrl(1),

Hope that helps, let me know what happens.
Dave Edis - Senior Developer
interactivetools.com