Use this code inplace of your code it will solve your problem
static final String URL = "http://www.sevenzaseo.com/androidapi.php";
// XML node keys
static final String KEY_TASK = "socialinfo"; // parent node
static final String KEY_FACEBOOKLIKE = "facebooklikes";
static final String KEY_TWITTERFOLL = "twitterfollowers";
static final String KEY_GOODLEPLUS = "googleplusfollowers";
static final String KEY_LINKEDIN = "linkedinfollowers";
static final String KEY_WESITEVIEW = "websiteviews";
ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>>();
XMLParser parser = new XMLParser();
String xml = parser.getXmlFromUrl(URL); // getting XML
Document doc = parser.getDomElement(xml); // getting DOM element
NodeList nl = doc.getElementsByTagName(KEY_TASK);
// looping through all task nodes <task>
for (int i = 0; i < nl.getLength(); i++) {
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
Element e = (Element) nl.item(i);
// adding each child node to HashMap key => value
map.put(KEY_FACEBOOKLIKE, parser.getValue(e, KEY_FACEBOOKLIKE));
map.put(KEY_TWITTERFOLL, parser.getValue(e, KEY_TWITTERFOLL));
map.put(KEY_GOODLEPLUS,parser.getValue(e, KEY_GOODLEPLUS));
map.put(KEY_LINKEDIN,"Linkined: " + parser.getValue(e, KEY_LINKEDIN));
map.put(KEY_WESITEVIEW,"WebsiteCount: " + parser.getValue(e, KEY_WESITEVIEW));
// adding HashList to ArrayList
menuItems.add(map);
}
Create this class in your package folder
public class XMLParser {
// constructor
public XMLParser() {
}
/**
* Getting XML from URL making HTTP request
* @param url string
* */
public String getXmlFromUrl(String url) {
String xml = null;
try {
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
xml = EntityUtils.toString(httpEntity);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
// return XML
return xml;
}
/**
* Getting XML DOM element
* @param XML string
* */
public Document getDomElement(String xml){
Document doc = null;
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
try {
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(xml));
doc = db.parse(is);
} catch (ParserConfigurationException e) {
Log.e("Error: ", e.getMessage());
return null;
} catch (SAXException e) {
Log.e("Error: ", e.getMessage());
return null;
} catch (IOException e) {
Log.e("Error: ", e.getMessage());
return null;
}
return doc;
}
/** Getting node value
* @param elem element
*/
public final String getElementValue( Node elem ) {
Node child;
if( elem != null){
if (elem.hasChildNodes()){
for( child = elem.getFirstChild(); child != null; child = child.getNextSibling() ){
if( child.getNodeType() == Node.TEXT_NODE ){
return child.getNodeValue();
}
}
}
}
return "";
}
/**
* Getting node value
* @param Element node
* @param key string
* */
public String getValue(Element item, String str) {
NodeList n = item.getElementsByTagName(str);
return this.getElementValue(n.item(0));
}
}