addAttribute
simplexml要素に属性を追加します。
addAttribute()
関数は、SimplexML要素に属性を追加するために使用されます。
ルート要素に属性を追加(<note>)および<body>要素を追加します。
<?php $ note = <<< xml <ノート> <to> george </to> <from> john </from> <見出し>リマインダー</heading> <body>会議を忘れないでください!</body> </note> XML ; $ xml = new SimplexmLelement ( $ note ) ; //ルート要素に属性を追加します $ xml- > addattribute ( "type" 、 "private" ) ; //ボディ要素に属性を追加します $ xml- > body- > addattribute ( "date" 、 "2014-01-01" ) ; echo $ xml- > asxml ( ) ; ?>
インスタンスを実行します
simplexmlelement :: addattribute ( name 、 value 、 ns )
パラメーター | 説明する |
---|---|
名前 | 必須。追加する属性の名前を指定します。 |
価値 | オプション。属性の値を指定します。 |
ns | オプション。プロパティの名前空間を指定します。 |