使用PHP设置XML属性[重复]

This question already has an answer here:

I'm trying to create .xml files with PHP, with a certain layout, using SimpleXMLElement. Currently I'm struggling setting an attribute to an element.

What I tried so far:

<?php
$att = 'name="tc1"';
$xml = new SimpleXMLElement('<configuration/>');

$track = $xml->addChild('testcase');
$track->attributes()->$att;
$track->addChild('pfad', "none");
$track->addChild('aktiv', "false");
$track->addChild('file', "none");
$track->addChild('wert', "none");


Header('Content-type: text/xml');
print($xml->asXML());
?>

I can't figure out, why it's only displaying:
( XML Output: )

<configuration>
  <testcase>
    <pfad>none</pfad>
    <aktiv>false</aktiv>
    <file>none</file>
    <wert>none</wert>
 </testcase>
</configuration>

...instead of:

...
<testcase name="tc1">
...

Could you please help me set the attribute correctly?

</div>
$track->addAttribute('name', 'tc1');

Source