blob: a531ccad46fbecac9dd67793539382f573ec55e2 (
plain)
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
--TEST--
SimpleXML: Adding an elements
--SKIPIF--
<?php if (!extension_loaded("simplexml")) print "skip"; ?>
--FILE--
<?php
$xml =<<<EOF
<people></people>
EOF;
function traverse_xml($xml, $pad = '')
{
$name = $xml->getName();
echo "$pad<$name";
foreach($xml->attributes() as $attr => $value)
{
echo " $attr=\"$value\"";
}
echo ">" . trim($xml) . "\n";
foreach($xml->children() as $node)
{
traverse_xml($node, $pad.' ');
}
echo $pad."</$name>\n";
}
$people = simplexml_load_string($xml);
traverse_xml($people);
$people->person = 'Joe';
$people->person['gender'] = 'male';
traverse_xml($people);
$people->person = 'Jane';
traverse_xml($people);
$people->person['gender'] = 'female';
$people->person[1] = 'Joe';
$people->person[1]['gender'] = 'male';
traverse_xml($people);
$people->person[3] = 'Minni-me';
$people->person[2]['gender'] = 'male';
traverse_xml($people);
$people->person[3]['gender'] = 'error';
traverse_xml($people);
?>
===DONE===
--EXPECTF--
<people>
</people>
<people>
<person gender="male">Joe
</person>
</people>
<people>
<person gender="male">Jane
</person>
</people>
<people>
<person gender="female">Jane
</person>
<person gender="male">Joe
</person>
</people>
Warning: main(): Cannot add element person number 3 when only 2 such elements exist in %s027.php on line %d
<people>
<person gender="female">Jane
</person>
<person gender="male">Joe
</person>
<person gender="male">Minni-me
</person>
</people>
<people>
<person gender="female">Jane
</person>
<person gender="male">Joe
</person>
<person gender="male">Minni-me
</person>
<person gender="error">
</person>
</people>
===DONE===
|