Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Developer
nimesh
Posts: 84
Registered: ‎01-28-2009
My Device: Not Specified

Fetching XML content

Hi to all,

<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).getFirstChild().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

 

 

 

 

 

Please use plain text.
Developer
vandzi
Posts: 40
Registered: ‎07-21-2009
My Device: ...............

Re: Fetching XML content

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 = .....}

)

Please use plain text.
New Developer
nimesh
Posts: 84
Registered: ‎01-28-2009
My Device: Not Specified

Re: Fetching XML content

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

Please use plain text.
Developer
vandzi
Posts: 40
Registered: ‎07-21-2009
My Device: ...............

Re: Fetching XML content

use for(int i = 0;i< e.length;i++){

 

 here try to catch exeption- not for all nodes,just for actual

 

}

Please use plain text.
New Developer
nimesh
Posts: 84
Registered: ‎01-28-2009
My Device: Not Specified

Re: Fetching XML content

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.

Please use plain text.
Developer
vandzi
Posts: 40
Registered: ‎07-21-2009
My Device: ...............

Re: Fetching XML content

so make "for( ..) "  for elements not for nodes
Please use plain text.
Developer
bikas
Posts: 984
Registered: ‎02-10-2009
My Device: Not Specified

Re: Fetching XML content

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


Please use plain text.