从PHP生成的XML编码

I am doing an assignment for class where I have to use a Java Servlet running on Tomcat and have it message a php file to scrape IMDB for movie information and return it as XML to the servlet. It seems to not want to accept any encoding I give it as I continuously get XML tags such as the ones below.

      <result cover="url" title="Pok&#xE9;mon" year="1998 TV Series" director="N/A" rating="7.8" details="http://www.imdb.com/title/tt0176385/"/>

Where title of Pokemon should have an accent over the e («é»). I have the following php code to generate the xml. (Important parts only)

    <?php header("Content-Type: text/xml; charset=utf-8");
    $xml = new DOMDocument();
    $rsp = $xml->appendChild($xml->createElement("rsp"));
    $xml->encoding = 'utf-8';

    $titleNames[$i] = utf8_encode($title_tmp[1]);

    $results = $rsp->appendChild($xml->createElement("results"));
    $results->setAttribute("total", $tableRows);

    $item->setAttribute("title", $titleNames[$i]);

    echo $xml->saveXML();
    ?>

Any help would be greatly appreciated in figuring out how to correctly display special characters!

It's impossible to say what's wrong from your code fragments (which don't even run) but $xml->encoding = 'utf-8' should work. Please compare:

$xml = new DOMDocument();
$rsp = $xml->appendChild($xml->createElement("rsp"));
$rsp->setAttribute("title", 'Pokémon');
echo $xml->saveXML();
/*
<?xml version="1.0"?>
<rsp title="Pok&#xE9;mon"/>
*/

... with:

$xml = new DOMDocument();
$xml->encoding = 'utf-8';
$rsp = $xml->appendChild($xml->createElement("rsp"));
$rsp->setAttribute("title", 'Pokémon');
echo $xml->saveXML();
/*
<?xml version="1.0" encoding="utf-8"?>
<rsp title="Pokémon"/>
*/

(These snippets are expected to be saved as UTF-8).