Hàm addChild () trong PHP
Thí dụ
Thêm một phần tử con vào phần tử <body> và một 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();
?>
Định nghĩa và Cách sử dụng
Hàm addChild () gắn một 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ả lại: | 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 chiếu PHP SimpleXML