Java tutorial
//package com.java2s; import java.io.IOException; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.w3c.dom.Document; import org.xml.sax.SAXException; public class Main { private static String USER_INFO_REQUEST_URL_BY_ID = "http://api.twitter.com/1/users/show.xml?user_id="; public static org.w3c.dom.Document getUserInfoByUserID(String userID) { return getXMLDocument(USER_INFO_REQUEST_URL_BY_ID + userID); } private static org.w3c.dom.Document getXMLDocument(String url) { Document document = null; DocumentBuilderFactory builderFactory; DocumentBuilder parser; // Try to load the document at the specified filepath into a DOM structure. // try { builderFactory = DocumentBuilderFactory.newInstance(); parser = builderFactory.newDocumentBuilder(); document = parser.parse(url); } catch (ParserConfigurationException p) { System.out.println("Error creating DOM parser."); System.out.println(" " + p.getMessage()); } catch (SAXException s) { System.out.println("XML document returned is not well-formed."); System.out.println(" URL : " + url); System.out.println(" " + s.getMessage()); } catch (IOException i) { System.out.println("Error accessing the stream."); System.out.println(" URL : " + url); System.out.println(" " + i.getMessage()); document = null; } return document; } }