private HashMap<String, String> readXmlString(String webReturnStr, String whichService){
HashMap<String, String> returnVal = new HashMap<String, String>();
webReturnStr = "<return>"+webReturnStr+"</return>";
System.out.println("Added root elements> "+ webReturnStr);
try {
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
InputSource src = new InputSource();
src.setCharacterStream(new StringReader(webReturnStr));
Document doc = builder.parse(src);
String requestid = "";
String pkgid = "";
String resultcode = "";
String status = "";
String pin = "";
String errorCode = "";
String description = doc.getElementsByTagName("description").item(0).getTextContent();
if(description.toUpperCase().contains("Success")){
resultcode = doc.getElementsByTagName("resultcode").item(0).getTextContent();
status = doc.getElementsByTagName("status").item(0).getTextContent();
pin = doc.getElementsByTagName("pin").item(0).getTextContent();
if("GEN".equals(whichService)){
requestid = doc.getElementsByTagName("requestid").item(0).getTextContent();
returnVal.put("requestid", requestid);
} else if("ACT".equals(whichService)){
pkgid = doc.getElementsByTagName("pkgid").item(0).getTextContent();
returnVal.put("pkgid", pkgid);
}
}else{
resultcode = doc.getElementsByTagName("resultCode").item(0).getTextContent();
errorCode = doc.getElementsByTagName("errorcode").item(0).getTextContent();
}
returnVal.put("resultcode", resultcode);
returnVal.put("description", description);
returnVal.put("status", status);
returnVal.put("pin", pin);
returnVal.put("errorCode", errorCode);
System.out.println("resultcode "+ resultcode);
System.out.println("description "+ description);
} catch (Exception e) {
//log.error("error in getting acct info. msisdn : " + msisdn + " : "
//+ e.getMessage());
e.printStackTrace();
}
return returnVal;
}
No comments:
Post a Comment