SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Guru
    Join Date
    Oct 2004
    Location
    uk
    Posts
    853
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Creating a xml page using mysql rows

    Hi guys what is the best way so that if I access


    listings.xml
    that it displays all the rows in my database in xml

    at the moment if I try to add php code to the xml page it does not work

    what is the best technique to use?

  2. #2
    SitePoint Wizard cranial-bore's Avatar
    Join Date
    Jan 2002
    Location
    Australia
    Posts
    2,634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    a .xml file is static, just like .html or .txt so it won't process embedded PHP
    You could:

    • create listings.php instead, which outputs xml (and serves the appropriate header), or
    • configure your server (e.g Apache) to parse .xml with PHP, which would allow you to embed PHP in the file (this will affect all .xml files), or
    • have a separate PHP script regularly write the static listings.xml file (e.g triggered to run every 10 minutes by a cron job). This is probably a good idea if the file is accessed a lot more than it changes.

    As for actually creating the dynamic XML doc, you could use the DOM Extension, or just dynamically output strings. Using DOM is more complex, but more reliable.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •