xref: /PHP-8.2/ext/simplexml/tests/026.phpt (revision 7f2f0c00)
1--TEST--
2SimpleXML: getName()
3--EXTENSIONS--
4simplexml
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--EXPECT--
35<people>
36  <person>Jane
37  </person>
38</people>
39