I’m trying to parse some XML and populate a List of blog posts. I’ve got the parsing bit working (at least it does when all I do is print them to screen). However when I try and set a class variable with the value using the proper setter method, and then push that complete object to my list, I’m getting a whole load of nulls. I’ve tried everything I can think of, and therefore would like to enlist the expertise that lurks here.
There is a lot of code, so I’ve posted it up to here:
Would really appreciate some tips as to where I’m going wrong.
Many thanks
You need to use a debugger here – I quickly threw together a BlogPost class for testing, and I see that your code is creating a BlogPost for every node individually – so
<rss>creates a blank BlogPost, as do<channel>,<atom:link>etc.I haven’t used SAX Parsers much (or this in-depth of XML parsing really), but I think you need to be only creating BlogPosts in the
endElementmethod perhaps.