如何使用PHP获取XML属性

This is my xml file:

<device name=" name ">
<interface>
    <ip > someip </ip>
</interface>
<display>
    <name> \\.\DISPLAY1 ( 1920 X 1080 )</name>
</display>
<output>
    <audio> Speakers (High Definition Audio </audio>
    <audio> Digital Audio (S/PDIF) (High De </audio>
    <audio> Digital Audio (S/PDIF) (High De </audio>
</output>

And this is my PHP code:

<body style="font-family: Arial">
<?php
    $xml=simplexml_load_file("device.xml");
    var_dump($xml);
    $attr = $xml->device->attributes()->name;
?>
<div id="leftDiv">
    <ul id="menu">
        <li><?php echo $attr; ?></li>
    </ul>
</div>
<div id="mainDiv">

</div>
<div id="rightDiv">

</div>

I want to reach device's name attribute and get its value, but I always get an error: main(): Node no longer exists in C:\xampp\htdocs\Project\index.php on line 30. Line 30 is this line: $attr = $xml->device->attributes()->name; What's wrong?

php file code

remove device from $xml->device->attributes()->name;

<body style="font-family: Arial">
<?php
    $xml=simplexml_load_file("device.xml");
    var_dump($xml);
    $attr = $xml->attributes()->name;
?>
<div id="leftDiv">
    <ul id="menu">
        <li><?php echo $attr; ?></li>
    </ul>
</div>
<div id="mainDiv">

</div>
<div id="rightDiv">

</div>

xml file

missing </device> to end of file so put it

<device name=" name ">
<interface>
    <ip > someip </ip>
</interface>
<display>
    <name> \\.\DISPLAY1 ( 1920 X 1080 )</name>
</display>
<output>
    <audio> Speakers (High Definition Audio </audio>
    <audio> Digital Audio (S/PDIF) (High De </audio>
    <audio> Digital Audio (S/PDIF) (High De </audio>
</output>
</device>