xref: /php-src/ext/simplexml/tests/028.phpt (revision 7f2f0c00)
1--TEST--
2SimpleXML: Adding an elements without text
3--EXTENSIONS--
4simplexml
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--EXPECT--
35<people>
36</people>
37<people>
38  <person name="John">
39  </person>
40</people>
41