-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.php
59 lines (51 loc) · 944 Bytes
/
test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
require_once('xml_merger.php');
$obj = new SimpleXMLElement('<company></company>');
$xmlMerger = new XmlGenerator();
//To create a node with id attribute
$emp1 = $xmlMerger->addXmlNode(
$obj,
'employee',
'',
['id' => '108064'],
'id'
);
$xmlMerger->addXmlNode(
$emp1,
'name',
'Mahesh Singh'
);
$xmlMerger->addXmlNode(
$emp1,
'mobile',
'01234567890'
);
// Replace previous node
// $xmlMerger->addXmlNode(
// $obj,
// 'employee',
// 'Mahesh Singh Rajawat',
// ['id' => '108064'],
// 'id'
// );
//again create a new node with attributes
$emp2 = $xmlMerger->addXmlNode(
$obj,
'employee',
'',
['id' => '108065'],
'id'
);
$xmlMerger->addXmlNode(
$emp2,
'name',
'John Doe'
);
$xmlMerger->addXmlNode(
$emp2,
'mobile',
'01234567890'
);
echo $xmlMerger->formatXml($obj->asXml());