PHP in XML file (or PHP file as XML one)

Wordpressor picture Wordpressor · Apr 15, 2011 · Viewed 7.9k times · Source

I have this code (part of bigger script):

flashvars.xmlSource = "datasource.xml";   

datasource.xml looks like:

<?xml version="1.0" encoding="utf-8"?>
<Object>
  <Contents>
    <Source="address" Title="title"></Source>
      <Description>&lt;h1&gt;New hot Features&lt;/h1&gt;&lt;p&gt;The all new Piecemaker comes with lots of new features, making it even more slick.&lt;/p&gt;&lt;p&gt;Just to mention a few - you can now specify unlimited transition styles, include your own SWF and Video files, add hyperlinks to images and info texts with all special characters.&lt;/p&gt;&lt;p&gt;We also impoved the navigation and the animation with animated shadows and pixel-perfect transitions.&lt;/p&gt;</Description>
(...)
  </Contents>
</Object> 

I want to generate datasource.xml dynamically using foreach loop.

I've just changed the file extension to .php but this is not that easy ;)

Any ideas?

Answer

anemgyenge picture anemgyenge · Apr 22, 2011

Funny or not, but try this one:

  1. leave your file extension to be "xml"
  2. where you wrote (...) write <? PHP CODE HERE ?>

So handle it as if it would be some html file. What I mean is:

<?xml version="1.0" encoding="utf-8"?>
<Object>
  <Contents>
    <Source="address" Title="title"></Source>
      <Description>&lt;h1&gt;New hot Features&lt;/h1&gt;&lt;p&gt;The all new Piecemaker comes with lots of new features, making it even more slick.&lt;/p&gt;&lt;p&gt;Just to mention a few - you can now specify unlimited transition styles, include your own SWF and Video files, add hyperlinks to images and info texts with all special characters.&lt;/p&gt;&lt;p&gt;We also impoved the navigation and the animation with animated shadows and pixel-perfect transitions.&lt;/p&gt;</Description>
<? create php loop here  ?>
  </Contents>
</Object>

Also note

this line

<Source="address" Title="title"></Source>

might be wrong (you assigned some value to the tagname), try

<Source name="address" Title="title"></Source>

or something like that.