Unable to insertBefore on an XML file

前端 未结 2 1734
粉色の甜心
粉色の甜心 2021-01-28 03:31

I\'m trying to write a script that will update an RSS XML file. I want it to take the existing file and add a new item to the top of the items list. I\'ve previous gotten it to

2条回答
  •  [愿得一人]
    2021-01-28 03:49

    I got it working. I changed these lines:

    $firstItem = $items->item(0);
    $firstItem->insertBefore($newItem,$firstItem->firstChild);
    

    To this line:

    $items->item(0)->parentNode->insertBefore($newItem,$items->item(0));
    

提交回复
热议问题