Rose
Rose

Reputation: 61

Extracting atom feeds from URL sets

I have a huge list of URL's and my task is to feed them to a java code which should spit out the atom contents. Is there an API library or how can I access them?I tried the below code but it does not show any output. I don't know what went wrong?

try {
URL url = new URL("https://www.google.com/search?hl=en&q=robbery&tbm=blg&
output=atom");
SyndFeedInput input = new SyndFeedInput();
SyndFeed feed = input.build(new XmlReader(url));
System.out.println("Feed Title: " + feed.getTitle());
for (SyndEntry entry : (List<SyndEntry>) feed.getEntries())
{
System.out.println("Title: " + entry.getTitle());
System.out.println("Unique Identifier: " + entry.getUri());
System.out.println("Updated Date: " + entry.getUpdatedDate());
for (SyndLinkImpl link : (List<SyndLinkImpl>) entry.getLinks())
{
System.out.println("Link: " + link.getHref());}           
for (SyndContentImpl content : (List<SyndContentImpl>) entry.getContents())
{
System.out.println("Content: " + content.getValue());
}

for (SyndCategoryImpl category : (List<SyndCategoryImpl>) entry.getCategories())
{
System.out.println("Category: " + category.getName());
}}}
catch (Exception ex) 
{
}

Upvotes: -1

Views: 163

Answers (2)

Nehal Shrivashtava
Nehal Shrivashtava

Reputation: 41

Every Atom feed have "feed" tag in it. So what you can do is read the url and check if it contains feed tag or not.

In java you can use inbuilt XMLparser library to do it -

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(url);
doc.getDocumentElement().normalize();

if (doc.getElementsByTagName("feed").getLength() > 0) {
       //do something
}

Upvotes: 0

evanchooly
evanchooly

Reputation: 6243

You can use Rome (http://rometools.org) to process atom feeds.

Upvotes: 1

Related Questions