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