07-21-2009 07:20 AM
<community> <name>Midtown Plaza Cafe</name>
The above code is a part of XML which I am having and I am using the following thing to fetch which is working fine :
st.name = e1.getElementsByTagName("name").item(0).getFirstCh
ild().getNodeValue().trim();
Now the problem is if I get a XML like this :
<community> </name>
And if I use the same code to fetch the XML then it is showing me Null error.
So if any one help on this part.
Thank you,
nimesh
07-21-2009 07:27 AM
I think, if your error is exception, u should try to catch it. Problem is that xml is missing open tag <name>. Or try something like this
if(e1.getElementsByTagName("name").item(0) != null){ st.name = .....})
07-21-2009 07:36 AM
Thank you for your suggestion, I have tried this it same like using try and catch but the issue is that I am having more than 10 Child Nodes than I have to use the same in all of them.
Is there any other way out.
Thank you,
nimesh
07-21-2009 09:11 AM
use for(int i = 0;i< e.length;i++){
here try to catch exeption- not for all nodes,just for actual
}
07-21-2009 09:17 AM
The child nodes are of different names like name, address, zip, etc.
So i guess for loop will be difficult on that part.
Thank,
nimesh.
07-21-2009 10:14 AM
07-21-2009 02:37 PM
Have a look at the xmldemo (ex: C:\Program Files\Research In Motion\BlackBerry JDE 4.3.0\samples\com\rim\samples\device\xmldemo) example provieded with the JDE.You will get the idea.
Regards
Bikas