Example 1 — Get Element Names
Print the name of the root element and of its child.
<?php
$book = simplexml_load_string('<book><title id="1">PHP</title></book>');
echo $book->getName(), PHP_EOL;
echo $book->title->getName(), PHP_EOL; How It Works
- simplexml_load_string() returns the root element, book.
- $book->getName() returns that name.
- $book->title selects the child element.
- getName() on the child returns title.

