Reading XML and Checking A Tag By Name

DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(result));
Document doc = builder.parse(is);

NodeList status = doc.getElementsByTagName("Success");

if (status == null || status.item(0) == null || status.item(0).getFirstChild() == null) {
System.out.println("Cannot parse Kwiktag response XML for retrieving token");

}

String success = status.item(0).getFirstChild().getNodeValue();
if (success != null && success.equals("true")) {
NodeList tokenList = doc.getElementsByTagName("Token");
if (tokenList != null) {
for (int i = 0; i < tokenList.getLength(); i++) {
token = tokenList.item(i).getFirstChild().getNodeValue();
}
}
}

Comments

Popular posts from this blog

CSM Quiz -2

Enabling WL-Proxy-SSL HTTP header in WebLogic

CSM Quiz -1