PHP addAttribute () 함수
예
루트 요소와 신체 요소는 속성을 추가합니다 :
<?php
$note=<<<XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
XML;
$xml=new SimpleXMLElement($note);
$xml->addAttribute("type","private");
$xml->body->addAttribute("date","2013-01-01");
echo $xml->asXML();
?>
$note=<<<XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
XML;
$xml=new SimpleXMLElement($note);
$xml->addAttribute("type","private");
$xml->body->addAttribute("date","2013-01-01");
echo $xml->asXML();
?>
»인스턴스를 실행
정의 및 사용
addAttribute () 함수는 SimpleXML을 요소에 속성을 추가 할 수 있습니다.
문법
addAttribute( name,value,ns );
参数 | 描述 |
---|---|
name | 必需。规定要添加的属性的名称。 |
value | 可选。规定属性的值。 |
ns | 可选。规定属性的命名空间。 |
기술 세부 사항
반환 값 : | 아니 반환 값이 없습니다. |
---|---|
PHP 버전 : | 5.1.3+ |
PHP SimpleXML을 참조 설명서