PHP attributes() 函數
實例
返回 XML 的 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>";
}
?>
$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>";
}
?>
定義和用法
attributes() 函數返回 XML 標籤的屬性和值。
語法
attributes(ns,is_prefix);
參數 | 描述 |
---|---|
ns | 可選。規定被檢索的屬性的命名空間。 |
is_prefix | 可選。規定一個布爾值。如果 ns 是首碼則為 TRUE,如果 ns 是 URI 則為 FALSE。默認是 FALSE。 |
技術細節
返回值: | 如果成功則返回一個 SimpleXMLElement 對象。 |
---|---|
PHP 版本: | 5.0.1+ |
