开发者

How to make xml file from php and mysql

My fellow friend is building site in flash and he uses XML files to access data in Flash.

I want to build editable CMS so that client can edit stuff.

Now开发者_如何学JAVA I don't' have any experience with XML.

I know PHP, HTML and Mysql very well.

So how can I change those already build XML files using Mysql and PHP?


Maybe going through

http://library.creativecow.net/articles/brimelow_lee/php_mysql/video-tutorial.php

will clear things for you.

Though, use it only to understand the concepts of XML and how it relates to mysql, php and swf. For real work look at libraries that deal with XML such as serializer mentioned in AvatarKava's answer.


Output the XML using PHP in exactly the same way the example XML file does and then put this at the top of your code:

header('Content-type: text/xml');

To create the XML file from the database just ouput the data the way you normally would adding XML tags in the right place. Eg:

<news>
<?
    while($item = mysql_fetch_array($data)){
    ?>
    <item>
        <url><?=$item['url']; ?></url>
        <title><?=$item['title']; ?></title>
    </item>
    }
?>
</news>

If you need more assistance, provide the XML file that was given to you with the flash file as a reference.


You probably should look at the PEAR XML Serializer Package. It makes it easy to convert a multi-dimensional array into XML.

Here's a decent tutorial: http://articles.sitepoint.com/article/xml-php-pear-xml_serializer

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜