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();
}
}
}
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
Post a Comment