PHP의 addChild () 함수
예
몸과 바닥 글 요소 요소의 자식 요소를 추가합니다 :
<?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);
// Add a child element to the body element
$xml->body->addChild("date","2013-01-01");
// Add a child element after the last element inside note
$footer=$xml->addChild("footer","Some footer text");
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);
// Add a child element to the body element
$xml->body->addChild("date","2013-01-01");
// Add a child element after the last element inside note
$footer=$xml->addChild("footer","Some footer text");
echo $xml->asXML();
?>
»인스턴스를 실행
정의 및 사용
의 addChild () 함수는 SimpleXML을 요소에 자식 요소를 추가합니다.
문법
addChild( name,value,ns );
参数 | 描述 |
---|---|
name | 必需。规定要添加的子元素的名称。 |
value | 可选。规定子元素的值。 |
ns | 可选。规定子元素的命名空间。 |
기술 세부 사항
반환 값 : | 그것은 XML 자식 요소에 SimpleXMLElement 개체에 추가를 반환합니다. |
---|---|
PHP 버전 : | 5.1.3+ |
PHP SimpleXML을 참조 설명서