<?xml version="1.0"?>
<Company>
<Test1>
<Employee>
<FirstName>Tanmay</FirstName>
</Employee>
<Employee>
<FirstName>Tanmay</FirstName>
</Employee>
</Test1>
</Company>
$doc = new DOMDocument;
$doc->load('company.xml');
function get_children($doc, $max_level, $level)
{
if($max_level > $level)
{
if($doc->count() > 0)
{
$childs = $doc->children();
return get_children($childs[0], $max_level, $level + 1);
}
else
return null;
}
return $doc;
}
$employee = get_children($doc, 2, 0); 2 - целевой уровень, 0 - стартовое значение уровня.