moving an existing node within the DomDocument:
<root>
<parent>
<child><name>Bob</name></child>
<child><name>Sue</name></child>
</parent>
</root>
$dom = new DomDocument();
$dom->load("sample.xml");
$parent_path = "/root";
$query = "//child[position() = 2]";
$query2 = "//child[position() = 1]";
$xpath = new DomXPath($dom);
$parent = $xpath->query($parent_path);
$under = $xpath->query($query);
$above = $xpath->query($query2);
$parent->item(0)->insertBefore($under->item(0), $above->item(0));
$dom->save("sample.xml");
Should produce:
<root>
<parent>
<child><name>Sue</name></child>
<child><name>Bob</name></child>
</parent>
</root>