i have a xmlfile:

```
$xml = <<<EOD
<?xml version="1.0" encoding="utf-8"?>
<metaData xmlns="http://www.test.com/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="test">
<qkc6b1hh0k9>testdata&amp;more</qkc6b1hh0k9>
</metaData>
EOD;

```

now i loaded it into a simplexmlobject and later on i wanted to get the inner of the "qkc6b1hh0k9"-node

```
$xmlRootElem = simplexml_load_string( $xml );
$xmlRootElem->registerXPathNamespace( 'xmlns', "http://www.test.com/" );

// ...

$xPathElems = $xmlRootElem->xpath( './'."xmlns:qkc6b1hh0k9" );
$var = (string)($xPathElems[0]);
var_dump($var);

```

I expected to get the string 

```
testdata&amp;more

```

... but i got

```
testdata&more

```

* Why is the \_\_toString() method of simplexmlobject converting my escaped specialchars to normal chars? Can I deactivate this behaviour?
* I came up with a temp-solution, which I consider as dirty, what do you say?

(strip\_tags($xPathElems[0]->asXML()))
* May the DOMDocument be an alternative?

Thanks for any help on my questions!

**edit**

problem solved, problem was not in the \_\_toString method of simplexml, it was later on when using the string with addChild

the behaviour as described above was totaly fine and has to be expected as you can see in the answers...

problems only came up, when the value was added to another xml-document via "addChild".
Since addChild doesn't escape the ampersand (<http://www.php.net/manual/de/simplexmlelement.addchild.php#103587>) one has to do it manually.