I have this XML:
In XML
order of nodes in same level is doesn't matter then you can't do this by theory, by practice user other library.
Numerical id order is maintained and made consecutive:
$objXML = new SimpleXMLElement(XML_FILE_NAME, null, true);
$picture = $objXML->xpath('picture');
usort($picture, create_function('$a,$b', 'return (string)$a["id"] - (string)$b["id"];'));
foreach ($pictures as $index => $node) $node["id"] = $index;