Topic
  • No replies
SystemAdmin
SystemAdmin
1830 Posts

Pinned topic Sax Parser - error : empty string

‏2012-07-30T21:47:43Z |
I am new to Sax parser and I am trying to parse an xml document. I am not validating it against the schema as I have no control over it and this is just a project.

In the xml file some of the elements are empty - and this is OK as they dont always need to have a value. It is getting as far as the below element and then it bombs out.

<num>
</num>

The error I am getting is :
java.lang.NumberFormatException: empty String
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1038)
at java.lang.Float.valueOf(Float.java:400)

It errors in the endElement. I am using the defaultHandler. Is their anyway I can get the parser to ignore empty strings and keep parsing the document?
if(qName.equalsIgnoreCase("num")){
Tmp.setNum(Float.valueOf(tmpString).floatValue());
}
Thanks in advance