當前位置: 首頁> 函數類別大全> addAttribute

addAttribute

向SimpleXML 元素添加屬性。
名稱:addAttribute
分類:未分類
所屬語言:php
一句話介紹:向SimpleXML 元素添加屬性。

定義和用法

addAttribute()函數用於向SimpleXML 元素添加屬性。

實例

向根元素(<note>)和<body> 元素添加屬性:

 <?php
$note = <<< XML
<note>
<to>George</to>
<from>John</from>
<heading>Reminder</heading>
<body>Do not forget the meeting!</body>
</note>
XML ;

$xml = new SimpleXMLElement ( $note ) ;
// 向根元素添加屬性
$xml -> addAttribute ( "type" , "private" ) ;
// 向body 元素添加屬性
$xml -> body -> addAttribute ( "date" , "2014-01-01" ) ;

echo $xml -> asXML ( ) ;
?>

運行實例

文法

SimpleXMLElement :: addAttribute ( name , value , ns )
參數 描述
name 必需。指定要添加的屬性的名稱。
value 可選。指定屬性的值。
ns 可選。指定屬性的命名空間。
同類函數
  • 創建新的SimpleXMLElement 對象。 __construct

    __construct

    創建新的SimpleXMLElement
  • 返回有關指定曆法的信息。 cal_info

    cal_info

    返回有關指定曆法的信息。
  • 檢索錯誤數組。 libxml_get_errors

    libxml_get_errors

    檢索錯誤數組。
  • Exception 對象的構造函數。 Exception

    Exception

    Exception對象的構造函數。
  • 上傳已打開的文件,並在FTP服務器上把它保存為文件(non-blocking)。 ftp_nb_fput

    ftp_nb_fput

    上傳已打開的文件,並在FTP服務器上把它
  • 關閉ZIP 文件中的一個項目。 zip_entry_close

    zip_entry_close

    關閉ZIP文件中的一個項目。
  • 在FTP 上執行一個程序/命令。 ftp_exec

    ftp_exec

    在FTP上執行一個程序/命令。
  • 返回ZIP 文件中的一個項目的實際文件尺寸。 zip_entry_filesize

    zip_entry_filesize

    返回ZIP文件中的一個項目的實際文件尺寸
熱門文章