PHP simplexml获取元素的属性和值

来源:互联网 发布:cactiez mysql 密码 编辑:程序博客网 时间:2024/04/20 22:38

返回 XML 的 body 元素的属性和值:

<!DOCTYPE html>

<html>
<body>

<?php
$note=<<<XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body date="2013-01-01" type="private">Don't forget me this weekend!</body>
</note>
XML;

$xml=simplexml_load_string($note);
foreach($xml->body[0]->attributes() as $a => $b)
{
     echo $a,'="',$b,"\"<br>";
}
?>
 

</body>

</html>



date="2013-01-01"
type="private"

0 0