How to make xml file from php and mysql

2020-03-26 06:31发布

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 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?

3条回答
成全新的幸福
2楼-- · 2020-03-26 06:32

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

查看更多
家丑人穷心不美
3楼-- · 2020-03-26 06:53

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.

查看更多
男人必须洒脱
4楼-- · 2020-03-26 06:55

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.

查看更多
登录 后发表回答