Membuat file XML
Dokumen XML dapat dibuat menggunakan script PHP menggunakan DOM [DocumentObject Model], yaitu interface standar untuk mengakses dan memanipulasi data. DOM dapat memodelkan atau merepresentasikan sebuah dokumen sebagai hierarki pohon dari objek.
Contoh Script : buat_xml.php
Pada script tersebut akan dokumen XML dengan induk sebagai element parent dan anak sebagai child. Pada element child terdapat 2 node yaitu anak pertama dan anak kedua. Kemudian disimpan sebagai file coba.xml yang hasilnya sebagai berikut :
Operasi penambahan node pada dokumen XML juga dapat dilakukan, seperti pada script berikut ini :
Contoh script : tambah_xml.php
Ditambahkan node anak ketiga pada element anak, yang hasilnya disimpan sebagai coba1.xml.
Mengedit Node
Contoh script : edit_xml.php
Menghapus Node
Contoh script : hapus_xml.php
Menambah Attribut
Contoh script : tambah_att_xml.php
Menampilkan XML
Contoh script : tampil_xml.php
Tutorial Selanjutnya Menyimpan dokumen XML ke dalam database
View Discussion
Improve Article
Save Article
View Discussion
Improve Article
Save Article
The DOMDocument::createElement[] function is an inbuilt function in PHP which is used to create a new instance of class DOMElement.
Syntax:
DOMElement DOMDocument::createElement[ string $name, string $value ]
Parameters: This function accepts two parameters as mentioned above and described below:
- $name: This parameter holds the tag name of the element.
- $value: This parameter holds the value of the element. The default value of this function creates an empty element. The value of element can be set later using DOMElement::$nodeValue.
Return Value: This function returns a new instance of class DOMElement on success or FALSE on failure.
Below programs illustrate the DOMDocument::createElement[] function in PHP:
Program 1:
Output:
GeeksforGeeks
Program 2:
Output:
GeeksforGeeks Noida
Reference: //www.php.net/manual/en/domdocument.createelement.php