php和xml按属性获取值

please help me need to get value by attributes for example

$xml = simplexml_load_file($filename);
print $xml->attribute->name('header');

output : HEADER only

and xml file

<template name="header" type="tpl">
**HEADER**
</template>
<template name="body" type="css">
BODY
</template>
<template name="footer" type="tpl">
FOOTER
</template>

The XML you give as an example raised various parsing errors. Now, I 'm assuming you have a workable, valid XML like that below:

<?xml version="1.0"?>
<templates>
    <template name="header" type="tpl">
    **HEADER**
    </template>
    <template name="body" type="css">
    BODY
    </template>
    <template name="footer" type="tpl">
    FOOTER
    </template>
</templates>

With that, accessing the template named header can be done in this way:

<?php
    $filename = "xmlparse01.xml";
    $xml = simplexml_load_file($filename);
    $reslt = $xml->xpath("//template[@name='header']");
    print trim($reslt[0]) . "
";
?>

I do not really understand your question, but if you want to know how to access the header attribute of an XML element, you can do:

$xml = simplexml_load_file($filename);
print $xml['header'];