- simplexml_load_string: documentation ( source)
<?php
$xml = "<root>
<parent>
<child name='Child1' />
<child name='Child2' />
<subparent>
naiya
</subparent>
</parent>
<child name='Child4' />
</root>";
$xml = simplexml_load_string( $xml);
foreach( $xml->xpath( '//child') as $child) {
$attributes = $child->attributes();
echo $attributes['name'] . "\n";
}