As long as the XML file is parsed by PHP, any embedded PHP within the XML file will execute normally. The problem you are likely to be experiencing is that by default, your XML file will not be parsed by PHP.
To get your web server to parse the XML file with PHP, you could rename your XML file with a .php extension.
If you'd prefer to keep it with a .xml extension and you're using Apache as your web server, you could configure Apache to parse all .xml files with PHP using something like the following in a .htaccess file:
<Files *.xml>
ForceType application/x-httpd-php
</Files>
or by adding .xml extension to this line in your httpd.conf :-
AddType application/x-httpd-php .php .xml
You may be able to do something similar with IIS...
As Weedpacket said, remember to use header('Content-Type: application/xml'); at top of your XML file to make sure correct headers are sent.