参数 | 描述 |
---|---|
name | 必需。规定属性的名称。 |
value | 必需。规定属性的值。 |
ns | 可选。规定属性的命名空间。 |
XML 文件:
<?xml version="1.0" encoding="ISO-8859-1"?> <note> <to>George</to> <from>John</from> <heading>Reminder</heading> <body>Dont forget the meeting!</body> </note>
PHP 代码:
<?php
$xml = simplexml_load_file("test.xml");
$xml->body[0]->addAttribute("type", "small")
;
foreach($xml->body[0]->attributes() as $a => $b)
{
echo $a,=",$b,";
}
?>
输出:
type="small"
制作:
http://www.7di.net 生活网搜集整理 参考: http://www.w3school.com.cn/php/func_simplexml_addattribute.asp |