PHP addAttribute() 함수
예시
루트 요소(<note>)와 <body> 요소에 속성을 추가합니다.
<?php
$note=<<<XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Do not forget me this weekend!</body>
</note>
XML;
$xml = new SimpleXMLElement($note);
// Add attribute to root element
$xml->addAttribute("type","private");
// Add attribute to body element
$xml->body->addAttribute("date","2014-01-01");
echo $xml->asXML();
?>
정의 및 사용
addAttribute() 함수는 속성을 SimpleXML 요소에 추가합니다.
통사론
SimpleXMLElement::addAttribute(name, value, ns)
매개변수 값
Parameter | Description |
---|---|
name | Required. Specifies the name of the attribute to add |
value | Optional. Specifies the value of the attribute |
ns | Optional. Specifies a namespace for the attribute |
기술적 세부 사항
반환 값: | 아무것도 |
---|---|
PHP 버전: | 5.1.3+ |
❮ PHP SimpleXML 참조