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
Trusted Contributor
hardikhamar
Posts: 159
Registered: ‎02-17-2011
My Device: Not Specified
Accepted Solution

problem about xml parse

hello.

 

i am working with bb jde 4.6.

 

i have on webservice and i want to value of city from this link.

 

i tried it,but it 's not getting any value,my code and link is as below:

 

 

 

 

code:

 

 class main extends MainScreen
 {
        public int i;
       
        public String title;
        public main()
        {
        
            // define variables later used for parsing
            Document doc;
            StreamConnection conn;
            try{
                System.out.println("hello 1");
                conn = (StreamConnection)Connector.open("http://vaikunth.kwetoo.com/mobile/getCSZ.php?csz=rokville,md;deviceside=true");
                System.out.println("coonection:"+conn);
                DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
                DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
                System.out.println("hello 2");
                docBuilder.isValidating();
                System.out.println("hel");
                doc = docBuilder.parse(conn.openInputStream());
                System.out.println("he");
                doc.getDocumentElement().normalize();
                System.out.println("hello 3");
                NodeList list = doc.getElementsByTagName("city");
                Element titleElem = (Element)list.item(0);
                System.out.println("hello 4");
                NodeList titleNode2 = titleElem.getChildNodes();
                        title = ((Node)titleNode2.item(0)).getNodeValue();
                        System.out.println("title");
                  
                        
                
                }//end try
                
            
            catch (Exception e){
                            }
      }  
   }       

please help me as soon as possible.

Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: problem about xml parse

 

i would suggest you start with one of the code samples.

as a sidenote, do not open network connections on the event thread, use a separate thread for all blocking operations.

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Trusted Contributor
hardikhamar
Posts: 159
Registered: ‎02-17-2011
My Device: Not Specified

Re: problem about xml parse

is it possible to use json in bb jde 4.6?

And if yes then ,can u give me a related example? 

Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: problem about xml parse

 

yes, you have to include json me as a library.

search the forum to find some samples.

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Trusted Contributor
hardikhamar
Posts: 159
Registered: ‎02-17-2011
My Device: Not Specified

Re: problem about xml parse

i download org.json.me and  add it in  project,what is next.

 

can u give me a example of it.

 

now when i try to import org.json.me ,it show me error that org.json.me not found.

 

i remind u that i work in bb jde4.6

 

Contributor
Sad_Bird
Posts: 30
Registered: ‎12-02-2010
My Device: BlackBerry 8520

Re: problem about xml parse

Well I think org.json.me is used to parse the JSON data not for the XML.

And if you want to parse XML data you have to use XML parsers not JSON parser.

DOM or SAX parser may be used to parse the XML docs....!!!

Adil Soomro

Trusted Contributor
hardikhamar
Posts: 159
Registered: ‎02-17-2011
My Device: Not Specified

Re: problem about xml parse

thanks for replay.

 

 

i know how to parse xml data.

 

 

but i give u link which is in json format,

that's why i want to use json,

 

i again send u link .

please see it and if possible it parse using xml then tell me how.

 

And it not possible then please give me related example.

 

i want to value of city from given link:

 

http://vaikunth.kwetoo.com/mobile/getCSZ.php?csz=roville,md

 

Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified
Trusted Contributor
hardikhamar
Posts: 159
Registered: ‎02-17-2011
My Device: Not Specified

Re: problem about xml parse

thanks for reply.

 

But i solve the problem myself using json.

New Contributor
khushi_palod
Posts: 9
Registered: ‎03-31-2011
My Device: 9700

Re: problem about xml parse

hi

 

i too need to parse json data....

 

can u plz help me.... how cud u solved ur problem.....?

 

its vry gud for me if u send me a sample code of parsing json...

 

 

thanx in advance!!!!

Deeps