Java Reference
In-Depth Information
builder.append(title);
builder.append("\",link=\"");
builder.append(link);
builder.append("\",date=\"");
builder.append(date);
builder.append("\"]");
return builder.toString();
}
}
The RSSItem class holds all of the attributes that are parsed from individual <item>
elements. These attributes, which can be accessed using getters, are listed here:
• Title
• Description
• Link
• Date
The RSSItem class includes a method, named load , which loads the item from an
<item> element. This method begins by looping through all of the child elements of the
<item> element.
NodeList nl = node.getChildNodes();
for (int i = 0; i < nl.getLength(); i++)
{
Node n = nl.item(i);
String name = n.getNodeName();
Each of the elements are checked to see if it is a <title> , <description> ,
<link> or <date> element. If the element is one of these, then the value of that element
is copied into the correct property.
if (name.equalsIgnoreCase("title"))
title = RSS.getXMLText(n);
else if (name.equalsIgnoreCase("link"))
link = RSS.getXMLText(n);
else if (name.equalsIgnoreCase("description"))
description = RSS.getXMLText(n);
else if (name.equalsIgnoreCase("pubDate"))
{
If the element is a date, then the date is parsed.
String str = RSS.getXMLText(n);
if (str != null)
date = RSS.parseDate(str);
}
}
This continues until all child elements of the <item> element have been processed.
Search WWH ::




Custom Search