As japos mentioned. Take care how you use isEmptyElement. After you are done looping through the attributes: isEmptyElement will be false. You can use moveToElement() to move the cursor back to the element and then you can use isEmptyElement like normal again.