Unable to insertBefore on an XML file

前端 未结 2 1732
粉色の甜心
粉色の甜心 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));
    
    0 讨论(0)
  • 2021-01-28 03:53

    "What am I missing?"

    The output: $rssDoc->save( 'filename.xml' ) http://php.net/domdocument.save.php

    0 讨论(0)
提交回复
热议问题