I'd like to rearrange elements in the file, I do not want to use another attribute for element ordering/arrangement.
+3
A:
I think it would be better to use the DOM extension for this rather than SimpleXML. SimpleXML as far as I know does not allow you to save changes back to a file easily (at least without using DOM anyway).
Once you have a reference to the DOMNode you want to move you can first remove it:
$node = $node->parentNode->removeChild($node);
Then put it before a different node:
$node = $otherNode->insertBefore($node);
This probably isn't a detailed enough answer - please can you add some more information about exactly what you are trying to achieve?
Tom Haigh
2009-06-05 08:21:19
I just want to rearrange (move them up or down, or to a specific order) nodes in one level. But your answer already solved my problem, lots of thanks! :D
2009-06-06 02:53:32