homepage Welcome to WebmasterWorld Guest from 54.161.228.29
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Processing .xml files with PHP
TheRealTerry




msg:1276616
 6:25 pm on Mar 10, 2005 (gmt 0)

I'm having trouble getting my dynamic XML file to serve as a .xml. I've used PHP to dynamically create a validating XML file except that it's served with a filename like: feed.php. What I want is to rename it as feed.xml and still have PHP pre-process it.

I've researched and determined that I needed to add "AddType application/x-httpd-php .xml" to my .htaccess file, which I've done. Now, I know I have the ability to use .htaccess files in my directories as I use them for mod_rewrites and permissions, but for some reason this does not force PHP to pre-process a file with a .xml extension. However, when I run the .xml feed URL through a validator it tells me "Feeds should not be served with the "application/x-httpd-php" media type", which would seem to indicate that Apache is sending the file out via PHP, but I can see all my PHP coding in the .xml file when I view it in a browser.

Any ideas what I missed?

 

coopster




msg:1276617
 6:33 pm on Mar 10, 2005 (gmt 0)

short_open_tag [php.net] perhaps?

TheRealTerry




msg:1276618
 8:21 pm on Mar 10, 2005 (gmt 0)

Shouldn't be an issue, I'm displaying that line with:
echo "<?xml version=\"1.0\"?>";
Which works fine in the .php file. The problem is that my PHP code is not being processed only when the file has an extension of .xml

py9jmas




msg:1276619
 8:37 pm on Mar 10, 2005 (gmt 0)

served with the "application/x-httpd-php" media type", which would seem to indicate that Apache is sending the file out via PHP,

That implies the opposite to me. Apache labels all files you want processed by PHP as application/x-httpd-php, then you tie the application/x-httpd-php media type to the PHP handler. The PHP processor then outputs the real media type that is seen by the client. The default media type is text/html, and you can change this with the PHP script with, eg
header("Content-type: application/xml")

The Web doesn't has no concept of "filename extensions". If the url [example.com...] returns Content-type: application/xml, then that URL points to a XML resource. Anything that tries to guess the filetype by its "extension" is broken. (Yes this includes IE).

TheRealTerry




msg:1276620
 9:57 pm on Mar 10, 2005 (gmt 0)

I already thought of that. The top of my file contains:
<?php
header('Content-type: text/xml');
echo "<?xml version=\"1.0\"?>";
?>

I've also tried application/xml as well and the result is the same.

And my .htaccess file has:
AddType application/x-httpd-php .xml

According to every tutorial I've found and every post I read on WebmasterWorld, everything is set up okay. However, regardless, when I try to view the XML file or validate it the PHP code shows as if it wasn't parsed at all.

TheRealTerry




msg:1276621
 5:51 pm on Mar 14, 2005 (gmt 0)

As a followup, I could find no solution to this. However, the feeds serve fine with a php extension, and have no trouble in news readers. The only problem is cosmetic, that the feeds don't have the .xml or .rss extension. Other than that they function as normal.

donb01




msg:1276622
 10:10 pm on Mar 14, 2005 (gmt 0)

I was having a similar situation, but my XML code was not contained in files, it was entered into a "template" form stored in a MySQL database and was parsed as needed.

In my situation my version of PHP was not compiled using the --with-xml option, so it was not set up to process the XML and would give me error messages about missing functions and the like.

I downloaded the latest version of PHP4, recompiled it and thought the problem was solved, but it stuck around. Later I found out that the directory the new modphp4 file was placed in was not where Apache expected it to be. As soon as I moved it into the right place it has been happily ever after.

Do you know your PHP was compiled with XML support?

gliff




msg:1276623
 2:47 pm on Mar 15, 2005 (gmt 0)

Terry,

Contact your host/server admin. Apache (assuming that's your web server) needs to be explicitly configured to allow the "AddType" directive in .htaccess files.

Specifically, you'll need the AllowOverride directive configured with a directive-type of "FileInfo" or "All".

You can read more in the apache documentation, at the following URL

[httpd.apache.org...]

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved