I'll try to read a xml file, but it goes to the catch block and returns null cause there some nodes null and I didn't know whats the best way to read this.
Here is a part of the xml file (I want only a part from the episode node it counts 134):
and here is my output:
Root element : Data
Nest Länge 134
Current Element :Episode
Staff id : 4712380
First Name : Blood Rush: Part One
Last Name : 2
Nick Name : de
Overview :
SeasonNumber : 0
lastupdated : 1391991457
seasonid : 488842
Catch-Block null
Assuming you wrote the Elements class, this is way to verbose and the method should handle the null case internally.
I would rather see
and have in Element
If you didn't write Element then you could do a similar thing with a static helper method.
Yes, that's the right Element class to use. But as Cary said, sometimes you're going to get a null value which means something like "no such thing was found" and you're going to need code to test for that possibility.
More than that, you're going to have to decide what to do when you get the null value. So far you've decided that you're going to terminate the program with no further processing, but clearly you're not happy with that decision.
You have to test each of them for null before proceeding to find the next one, otherwise you're going to get an NPE. The code to do that is like Carey's but more complicated.
Why are you calling toString()? Unless that object has overridden the Object#toString() method you get the object's hashCode (i.e. ID), which is what your output shows.
The code you had with item(0).getContent() gave you what you wanted, didn't it? What are you trying to achieve that you didn't have before?
what I want is to store selected (the part from the element) in my database and for me is it equal if its null or filled up with data...
I have make toString() to get any result.
When I try it with the item(0).getTextContent, it goes in the first node and then runs in the catch with null like this
Current Element :Episode
id : 4712380
EpisodeName : Blood Rush: Part One
EpisodeNumber : 2
Language : de
Overview :
SeasonNumber : 0
lastupdated : 1391991457
seasonid : 488842
Catch-Block null
I have try XML Read and it worked but I cant select item for item
maybe I have a node in my brain I don't know
And the way to store the data from the file in the database is equal ...
I highly recommend going to the Javadocs and looking up the DOM methods that you are calling and to see what types they are returning and whether or not they throw exceptions.
I showed you two methods, one that gets text that you'll have to print yourself and one to also do the printing. You are using the one that doesn't print but you've taken away all the code that prints the string.
Edit: Never mind. I see you used a diifferent method name.