This is my xml to parse
<metadata>
<groupId>org.chromium</groupId>
<artifactId>chromedriver-win32</artifactId>
<versioning>
<release>2.14</release>
<versions>
<version>2.14</version>
</versions>
<lastUpdated>20150610112540</lastUpdated>
</versioning>
</metadata>
While I am trying to parse the above XML, I am getting NullPointerException
even though I have handled the null check. Below is the code
private String getVersionFromNode(Element eElement) {
String version = null;
// Get the latest version
String tagName = "latest";
try {
version = eElement.getElementsByTagName(tagName).item(0).getTextContent();
// If latest version is not available take the release
// version
if ( version.isEmpty() || null == version || "null" == version) {
tagName = "release";
version = eElement.getElementsByTagName(tagName).item(0).getTextContent();
}
}
catch (NullPointerException e) {
System.out.println("not able to parse " + tagName + " tag " + e.getMessage());
}
return version;
}
When the version is null, it should enter in below block.
if ( version.isEmpty() || null == version || "null" == version) {
tagName = "release";
version = eElement.getElementsByTagName(tagName).item(0).getTextContent();
}
What should be solution for this problem?