Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Awlex182758y@Makenshi It's more about these if brackets.
Simple and short solution:
If (nowItem = parser.getLocalName().equals("item"))
item = new Item(); -
@Awlex I once too assigned variables in if statements, until I had this one bug that I could not figure out for hours that was caused by my eyes mistaking the assignment for a comparison. Don't. Just don't assign variables in if statements.
-
@Awlex Oh ok. I thought you meant the "zombie code". Although I disagree with your statement. It's a bad practice to assign values in if blocks. Also the comparisons should be "string".equal(value) to avoid NPE.
For code reviews you should be aware of those things. ;-) Also the long switch construction is really ugly. -
Awlex182758y@Makenshi I know, that this long switch isn't an eyecatcher, but Is there really a better way when parsing XML manually?
-
@Awlex In case of XML parsing I would go with the approach to just extract the code from the case statements into methods with descriptive names. Normally this would be to brittle, as you have to would have to modify the switch statement each time a new "case" is needed. Since the number of XML tokens in your SAX parser is known, this would seem ok. You could maybe take a look at the Handler api from SAX2. It offers separate methods for the SAX parsing approach.
My eyes...
undefined