I want to write xml with php and Im using the code in this tutorial:


I've made the php page and everything looks fine when I access the PHP file, I get the XML structure and all.

the problem is, it works only if the file in in .php extension. I want to call the file when the .xml extension, how to do that?

Thnx, and sorry for the probably noobish question.

7 Years
Discussion Span
Last Post by kokoro90


The only way I can think of to do this would be to add a rewrite rule in your .htaccess file:

RewriteEngine On
RewriteRule ^/path/yourfile.xml$   /path/yourfile.php

This will basically execute the php file in the background while the user only sees the .xml extension.


Thanks for the response, but this didn't help, now whenever I access the file with .xml extension I get an XML error pointing to the end of the php script (after the ?>) and when viewing the source of the page I can see the php script. so the php script was parsed as XML.

Any ideas?



sorry, I think I typed something wrong in the .htaccess file, now it works, but is it normal that I can't see the XML as a regular XML file? and I see the title of the book as the title of the page? is it because of this line:

$title = $doc->createElement( "title" );
  $doc->createTextNode( $book['title'] )
  $b->appendChild( $title );

So probably I have 2 problems:

1. the files looks like an echo of a php, no pink background, no XML tags visible and so on.

2. the title of the page is the title of the book.



Is this problem only occurring if you access it using the .xml extension, or even when you are calling the .php directly?

Also, if you do a "view source", does the file look correct?


when viewing the source it looks like a regular XML:

<?xml version="1.0"?>
    <title>Romeo and Juliet</title>
    <desc>William Shakespeare</desc>

The page looks exactly the same, whether I access it using .xml extension or .php

any ideas?


You are not trying to display the XML as-is, right? I think you should try to feed it to whoever/whatever will consume this generated xml and see if it works.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.