1<?php
2
3 $dom = new DOMDocument();
4
5 $dom->encoding = 'utf-8';
6
7 $dom->xmlVersion = '1.0';
8
9 $dom->formatOutput = true;
10
11 $xml_file_name = 'movies_list.xml';
12
13 $root = $dom->createElement('Movies');
14
15 $movie_node = $dom->createElement('movie');
16
17 $attr_movie_id = new DOMAttr('movie_id', '5467');
18
19 $movie_node->setAttributeNode($attr_movie_id);
20
21 $child_node_title = $dom->createElement('Title', 'The Campaign');
22
23 $movie_node->appendChild($child_node_title);
24
25 $child_node_year = $dom->createElement('Year', 2012);
26
27 $movie_node->appendChild($child_node_year);
28
29 $child_node_genre = $dom->createElement('Genre', 'The Campaign');
30
31 $movie_node->appendChild($child_node_genre);
32
33 $child_node_ratings = $dom->createElement('Ratings', 6.2);
34
35 $movie_node->appendChild($child_node_ratings);
36
37 $root->appendChild($movie_node);
38
39 $dom->appendChild($root);
40
41 $dom->save($xml_file_name);
42
43 echo "$xml_file_name has been successfully created";
44?>