I have an xml document that has (I think) a little bit strange structure that hassles me a bit. It looks like the following:
<Test1>84.23</Test1>
<Test2>2014-12-01</Test2>
<Test3></Test3>
<Test4>Green</Test4>
<Test5>Bottle</Test5>
<Test6/>
<Test7/>
The problem is the structure for the tag <Test3></Test3>, as you can se the other tags - when empty - delivers just e.g. <Test6/>
For the "normal" tags (e.g. <Test6/>) I can use the following code to check if it is empty, null or returning 0.
if(eElement.getElementsByTagName("Test6").item(0).getTextContent().isEmpty()
|| eElement.getElementsByTagName("Test6").item(0).getTextContent().trim().length() == 0
|| eElement.getElementsByTagName("Test6").item(0).getTextContent() == null)
{
array[1] = null;
}
But when applying the above code on the <Test3></Test3>-tag structure I always get java.lang.NullPointerException
I have also tried applying "".equals(eElement.getElementsByTagName("Test6").item(0).getTextContent()) in my if statement but still get the null exception thrown.
All I want to do is to set the array[1] to null if the Test3 -tag is empty, 0 or null. What am I doing wrong and how do I fix it?
No comments:
Post a Comment