Hàm addChild() của PHP
Ví dụ
Thêm phần tử con vào phần tử <body> và phần tử <footer> mới:
<?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 a child element to the body element
$xml->body->addChild("date","2014-01-01");
// Add a child element after the last element inside note
$footer = $xml->addChild("footer","Some footer text");
echo $xml->asXML();
?>
Chạy ví dụ »Định nghĩa và cách sử dụng
Hàm addChild() nối thêm phần tử con vào phần tử SimpleXML.
Cú pháp
SimpleXMLElement::addChild( name, value, ns )
Giá trị tham số
Parameter | Description |
---|---|
name | Required. Specifies the name of the child element to add |
value | Optional. Specifies the value of the child element |
ns | Optional. Specifies a namespace for the child element |
Chi tiết kỹ thuật
Giá trị trả về: | Một đối tượng SimpleXMLElement đại diện cho phần tử con được thêm vào nút XML |
---|---|
Phiên bản PHP: | 5.1.3+ |
❮ Tham khảo PHP SimpleXML