Nested XML Tag in PHP

Now let's have a nested tag:

test.xml<root>
  <tag>
    <elem>text</elem>
  </tag>
</root>

Let's get the value of the nested tag. To do this, you need to perform a chain of calls:

php<?php
  echo $xml->tag->elem; // 'text'
?>
Задание 1

Given the following XML:

html<root>
  <tag1>
    <tag2>
      <tag3>
        text
      </tag3>
    </tag2>
  </tag1>
</root>

Display the text of the innermost tag on the screen.