Kleist wrote:
Unfortunally I have only PHP 4.3.1 on my server, and this
will not do. But anyway thanks for replay
The following looks a bit cumbersome but appears to do the trick:
<?php
if (!$dom = domxml_open_mem('<doc><child id="0" /><child id="2" /></doc>'))
{
echo "Error while parsing the document\n";
exit;
}
$xpath = xpath_new_context($dom);
$root = $dom->document_element();
$element = $dom->create_element('child');
$element->set_attribute('id', 1);
$nodeset = xpath_eval($xpath, '//child[@id=0]');
$node = $nodeset->nodeset[0];
if ($sibling = $node->next_sibling()) {
$root->insert_before($element, $sibling);
} else {
$node->append_sibling($element);
}
echo "<pre>";
$xmlfile = $dom->dump_mem();
echo htmlentities($xmlfile);
echo "</pre>";
?>
JW