xref: /PHP-5.5/ext/simplexml/tests/028.phpt (revision 610c7fbe)
1--TEST--
2SimpleXML: Adding an elements without text
3--SKIPIF--
4<?php if (!extension_loaded("simplexml")) print "skip"; ?>
5--FILE--
6<?php
7$xml =<<<EOF
8<people></people>
9EOF;
10
11function traverse_xml($xml, $pad = '')
12{
13  $name = $xml->getName();
14  echo "$pad<$name";
15  foreach($xml->attributes() as $attr => $value)
16  {
17    echo " $attr=\"$value\"";
18  }
19  echo ">" . trim($xml) . "\n";
20  foreach($xml->children() as $node)
21  {
22    traverse_xml($node, $pad.'  ');
23  }
24  echo $pad."</$name>\n";
25}
26
27
28$people = simplexml_load_string($xml);
29traverse_xml($people);
30$people->person['name'] = 'John';
31traverse_xml($people);
32
33?>
34===DONE===
35--EXPECTF--
36<people>
37</people>
38<people>
39  <person name="John">
40  </person>
41</people>
42===DONE===
43