Sniffing content is one method. But note that atom uses namespaces, and you are creating a non namespace aware parser.
public boolean isAtom(String URL) throws ParserConfigurationException, SAXException, IOException{
DocumentBuilderFactory f = DocumentBuilderFActory.newInstance();
f.setNamespaceAware(true);
DocumentBuilder builder = f.newInstance().newDocumentBuilder();
Document doc = builder.parse(URL);
Element e = doc.getDocumentElement();
return e.getLocalName().equals("feed") &&
e.getNamespaceURI().equals("http://www.w3.org/2005/Atom");
}
Note also that you cannot compare using equalsIgnorCase(), since XML element names are case sensitive.
Another method is to react on the Content-Type header, if it is available in a HTTP GET request. Content-Type for ATOM would be application/atom+xml
and for RSS application/rss+xml
. I would suspect though, that not all RSS feed can be trusted to correctky set this header.
A third option is to look at the URL suffix, e.g. .atom and .rss.
The last two methods are easily configurable if you are using Spring or JAX-RS