8 messages in com.googlegroups.google-desktop-developerRe: Go to random item in RSS feed| From | Sent On | Attachments |
|---|---|---|
| Robert | 17 Jun 2008 14:08 | |
| Bijoy Thangaraj | 17 Jun 2008 20:44 | |
| Robert | 18 Jun 2008 11:03 | |
| Bijoy Thangaraj | 18 Jun 2008 12:34 | |
| Robert | 18 Jun 2008 13:49 | |
| Bijoy Thangaraj | 19 Jun 2008 10:53 | |
| Robert | 19 Jun 2008 14:05 | |
| Robert | 22 Jun 2008 18:51 |
| Subject: | Re: Go to random item in RSS feed![]() |
|---|---|
| From: | Robert (Prof...@gmail.com) |
| Date: | 06/22/2008 06:51:13 PM |
| List: | com.googlegroups.google-desktop-developer |
I scrapped the code above, and worked out this (based on the SimpleXMLParser example)
The new code works as desired.
SimpleXmlParser.prototype.getItems = function(key) { var xmlDoc = this.xmlDoc; var items = []; if (this.parseError.errorCode != 0) { debug.error("SimpleXmlParser ERROR: " + this.parseError.reason); } else { var objNodeList = xmlDoc.getElementsByTagName(key); for (var i = 0; i < objNodeList.length; ++i) { var xmlItem = objNodeList.item(i); var item = {}; var added = false; for (var j = 0; j < xmlItem.childNodes.length; ++j) { var child = xmlItem.childNodes.item(j); if (child.childNodes.length > 0) { var name = child.nodeName; var value = child.childNodes[0].nodeValue; item[name] = value; added = true; } } if (added) { items.push(item); } else { debug.trace("item " + i + " did not have any child elements. Omitted.") } } }
var aa = Math.floor(Math.random()*i); var item_title = items[aa]['title']; Product.innerText = item_title; var item_link = items[aa]['link']; Product.href = item_link;
return items; }
On Jun 19, 10:06 pm, Robert <Prof...@gmail.com> wrote:
The feed opens now. The server was timing out for me earlier today..
On Jun 19, 6:53 pm, "Bijoy Thangaraj" <jspl...@gmail.com> wrote:
Hi Robert,
The feed doesn't seem to open for me.
On Thu, Jun 19, 2008 at 2:20 AM, Robert <Prof...@gmail.com> wrote:
Sure
The feed is at
On Jun 18, 8:34 pm, "Bijoy Thangaraj" <jspl...@gmail.com> wrote:
The syntax looks correct. Which feed are you trying to parse? Can you share the URL?
On Wed, Jun 18, 2008 at 11:33 PM, Robert <Prof...@gmail.com> wrote:
Thanks for the help.
I modified it like this -
var titleArray = new Array(); var linkArray = new Array();
var elem = doc.getElementsByTagName("item");
for(var i = 0;i < elem.length ;i++) { if (elem != null && elem.length > 0) { for (var node = elem[0].firstChild; node != null; node = node.nextSibling) { if (node.nodeName == "title") { title = node.firstChild.nodeValue; titleArray.push(title); } if (node.nodeName == "link") link = node.firstChild.nodeValue; linkArray.push(link); }
} Product.href=linkArray[2] Product.innerText= titleArray[2]
I put 2 in place of a random currentIndex value for testing, trying to read the second item in the array, and I am getting blank information returned. Am I missing something in how the arrays are defined?
Thanks Robert
On Jun 18, 4:45 am, "Bijoy Thangaraj" <jspl...@gmail.com> wrote:
Hello Robert,
You can have the titles and links stored in an Array. Generate a random number and access that random index if it exists.
For each item, if (node.nodeName == "title") { title = node.firstChild.nodeValue; titleArray.push(title); } if (node.nodeName == "link") { link = node.firstChild.nodeValue; linkArray.push(link); }
Generate a random currentIndex and get those links and titles
linkArray[currentIndex] titleArray[currentIndex]
Hope that helps. Let me know if you are stuck.
On Wed, Jun 18, 2008 at 2:38 AM, Robert <Prof...@gmail.com> wrote:
Hello -
I am new to developing with the Google Desktop API, Javascript, XML, etc.
I am trying to load names and URLs out of a RSS feed, with the goal of creating a Gadget that shows a name that can be clicked and go to the URL for more information.
I have been able to get things to work with the first item in the feed. Now I would like to have the gadget load different name/URL pairs every day from the feed. This is what I have so far -
var elem = doc.getElementsByTagName("item"); if (elem != 0 && elem.length > 0) { for (var node = elem[0].firstChild; node != null; node = node.nextSibling) { if (node.nodeName == "title") title = node.firstChild.nodeValue; if (node.nodeName == "link") desc = node.firstChild.nodeValue; } }
Product.href = desc; Product.innerText = title;
The name is stored in "title", the URL for more information is stored in "link" in the feed.
Any help would be appreciated.
-- Thanks and Regards, Bijoy Thangarajhttp://www.jsplash.com
-- Thanks and Regards, Bijoy Thangarajhttp://www.jsplash.com
-- Thanks and Regards, Bijoy Thangarajhttp://gadgets.jsplash.com
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Desktop Developer Group" group.
To post to this group, send email to Goog...@googlegroups.com
To unsubscribe from this group, send email to
Goog...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/Google-Desktop-Developer?hl=en
-~----------~----~----~----~------~----~------~--~---




