Matthew Croud wrote: > The XML looks like: > > <Clothes> > <Item>...</Item> > <Item>...</Item> > <Item>...</Item> > <----- new items are added here > <Clothes> > > This is what my code looks like: > > $y = $dom -> getElementsByTagName("item"); > $dom -> documentElement -> insertBefore($Xitem,$y); > > If trying to pass the top most "item" node to insertbefore() but without > any luck. Any ideas ?
been very verbose on purpose so you get the idea -> $newItem = ''; // your new node to insert $items = $dom->getElementsByTagName("item"); $firstItem = $items->item(0); $clothes = $firstItem->parentNode; $newItem = $clothes->insertBefore( $newItem , $firstItem ); short version is.. $y = $dom->getElementsByTagName("item")->item(0); $Xitem = $y->parentNode->insertBefore( $Xitem, $y ); please note: haven't checked this but should all work. problem with your code was you were supplying $y which was a DOMNodeList; and as the docs say: "If not supplied, newnode is appended to the children." which yuo can translate as it'll be appended if the second param of insertBefore is incorrect i guess. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php