Topic: Having Trouble Properly Adding Items to Newsfeed with PHP Script (Read 819 times)
Kill the googlebot
Gender:
Posts: 6
44 credits Members referred : 0
« on: Aug 27, 2007, 12:55:52 AM »
Hello, all. I'm having trouble with a PHP script I'm writing to update an RSS newsfeed. It adds a new <item> to the newsfeed but it adds it at the bottom instead of at the top of the list. How can I have it add the new <item> as the first one on the list instead of the last?
$elements is a DOMNodeList with 10 items. I want to zero in on the first item (index "0") so I try to do that with the 2nd line of code. But the 3rd line of code keeps giving me errors. I want to insert a new <item></item> just before the first item.
I get this: Fatal error: Uncaught exception 'DOMException' with message 'Hierarchy Request Error'
What does that even mean? Can anyone tell me what I'm doing wrong? I'm guessing I should pass different arguments to the insertBefore command but how do I know which arguments to pass?
Nikolas' Servant Child
Posts: 30
184 credits Members referred : 0
« Reply #8 on: Aug 29, 2007, 09:42:44 AM »
You can't insert the same element again --- you have to clone it first, or create a new one. Also, you need to insert it into the parent node, otherwise your new node becomes a child of the reference node.
Kill the googlebot
Gender:
Posts: 6
44 credits Members referred : 0
« Reply #9 on: Aug 29, 2007, 08:25:09 PM »
anthonyw, I wanted to thank you for your help. My script is running now and doing what I wanted. One question, though: now that I know how to clone an existing node: $element->cloneNode(true)
How do I create a new one? For example, a new <item></item> (it doesn't have to have anything between the tags).
anthonyw, I wanted to thank you for your help. My script is running now and doing what I wanted. One question, though: now that I know how to clone an existing node: $element->cloneNode(true)
How do I create a new one? For example, a new <item></item> (it doesn't have to have anything between the tags).
Code:
$element->cloneNode(false)
will create a new empty element of the same type as the original. Alternatively
Code:
$dom_xml->createElement("item")
will create an entirely new node of a specified element type.
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=7044