I have an XML as follows:
<info>
<userId>Admin</userId>
<userNotes></userNotes>
</info>
I am trying to parse this in JAVA. and here is my code snippet:
NodeList userIdNodeList = document.getElementsByTagName("userId");
if (userIdNodeList!=null) {
userId = userIdNodeList.item(0).getChildNodes().item(0).getNodeValue().trim();
}
NodeList userNotesNodeList = document.getElementsByTagName("userNotes");
if (userNotesNodeList!=null) {
userNotes = userNotesNodeList.item(0).getChildNodes().item(0).getNodeValue().trim();
}
But the above code is throwing a NULL pointer error because the userNotes element is empty.
Any ideas on how to fix this?