My experience of XML and related technologies is limited, but cannot you or someone else modify the xspf file to include the encode() function I suggested?
Added: I'm guessing it's like this:
the php is requested;
this php page loads and executes the xspf file, which is an XML-Transform file - which transforms an XML document from one XML-structure to another;
the transform get's its source data from either an XML-document or a database - I suspect, a database;
this all executes on the server before returning the (final) XML data.
So there is no
source to modify, unless the database-data itself can be modified. So, as I see it, modifying the xspf.xml is the solution.
But I may be completely wrong

.