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
Developer
Posts: 777
Registered: ‎07-21-2012
My Device: 9810
My Carrier: 0

Re: problem is xml parsing

Yes you are right...

i understand the logic .But not able to do coding since morning.Please sir do a little bit coding then i will do next parts

and call other web service.

Only help in this webservice

Thanks 

Developer
Posts: 777
Registered: ‎07-21-2012
My Device: 9810
My Carrier: 0

Re: problem is xml parsing

I will understand using debugging if you do some part of coding .
Thanks in advance
Developer
Posts: 16,992
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: problem is xml parsing


ravi1989 wrote:
Please sir do a little bit coding then i will do next parts

Here is how it works:

I do a little bit coding, you do a little bit paying

----------------------------------------------------------
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
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: problem is xml parsing

As you can tell from the output, you are correctly obtaining the CharacteristicValue element.

 

This element is a Node.  But it also contains a number of children, so from this Node, you can onbtain a NodeList.  This is what you should do.  Then go through the NodeList of the children and see what Elements you find there.

 

So when you know you have an CharacteristicValue element, you get get the children of this Node, as a NodeList, using getChildNodes().

Developer
Posts: 777
Registered: ‎07-21-2012
My Device: 9810
My Carrier: 0

Re: problem is xml parsing

Till now i am not able to do dis..

Please help

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: problem is xml parsing

This is not the answer.  It is just code that I hope will help you understand what is going on here.  

 

You can put this code in place of your current for loop if you want to try it.  But I hope you don't have too. 

 

Instead read the code, review the API, review your understanding of XML, look at your XML input and see if you can figure out what it is going to do. If you can't understand what it is doing, then review it all again.  Don't try the code until you know what it is going to do. 

 

Code has NOT been compiled.  Or tested (obviously!). 

 

Good luck:

 

    	for (int i=0;i<list.getLength();i++){
	       	 Node node1 = list.item(i);
	         System.out.println("* Processing Level 1: item: " + Integer.toString(i));
	         short node1Type = node1.getNodeType();
	         if ( node1Type == Node.ELEMENT_NODE ) {
	        	 System.out.println("* Element: " + node1.getNodeName() );
	         }
	         if ( node1.hasChildNodes() ) {
	        	 NodeList level2List = node1.getChildNodes();
	        	 for ( int j = 0; j < level2List.getLength(); j++ ) {
	        		 Node node2 = level2List.item(j);
	        		 System.out.println("* Processing Level 2: item: " + Integer.toString(i));
	    	         short node2Type = node2.getNodeType();
	    	         if ( node2Type == Node.ELEMENT_NODE ) {
	    	        	 System.out.println("* Element: " + node2.getNodeName() );
	    	         }
	    	         if ( node2.hasChildNodes() ) {
	    	        	 NodeList level3List = node2.getChildNodes();
	    	        	 for ( int k = 0; j < level3List.getLength(); k++ ) {
	    	        		 Node node3 = level2List.item(k);
	    	        		 System.out.println("* Processing Level 3: item: " + Integer.toString(k));
	    	    	         short node3Type = node3.getNodeType();
	    	    	         if ( node3Type == Node.ELEMENT_NODE ) {
	    	    	        	 System.out.println("* Element: " + node3.getNodeName() );
	    	    	         }
	    	        	 }
	    	         }
	        	 }
	         }
       }//end for

 

Developer
Posts: 777
Registered: ‎07-21-2012
My Device: 9810
My Carrier: 0

Re: problem is xml parsing

I understand tittle bit , till now i am not able to get what i want.i get null point exception after 2 or 3 iteration .Please help me.

 

 

[0.0] FocusHistory: Focus gained; App xmlparsing; Component mypackage.MyScreen
[0.0] *******************************doc****net.rim.device.api.xml.jaxp.DOMDocumentImpl@1eee8868
[0.0] *******************************list****net.rim.device.api.xml.jaxp.DOMNodeListImpl@1bb63976
[0.0] CharacteristicValue 27
[0.0] * Processing Level 1: item: 0
[0.0] * Element: CharacteristicValue
[0.0] * Processing Level 2: item: 0
[0.0] * Processing Level 2: item: 0
[0.0] * Element: Characteristic
[0.0] java.lang.NullPointerException

 This is my run method

 

  public void run()
        {
            
           
            try{
                
            	
                DocumentBuilderFactory docBuilderFactory= DocumentBuilderFactory. newInstance(); 
                  
                DocumentBuilder docBuilder= docBuilderFactory.newDocumentBuilder();
                  
               
                FileConnection fc=(FileConnection)Connector.open("file:///SDCard/a.xml");
              InputStream  is=fc.openInputStream();
            doc= docBuilder.parse(is);
            System.out.println("*******************************doc****"+doc);
                doc.getDocumentElement ().normalize ();
                NodeList list=doc.getElementsByTagName("CharacteristicValue");
                System.out.println("*******************************list****"+list);
                System.out
                .println("CharacteristicValue " + list.getLength());
                
               if(list!=null &&list.getLength()>0){
                for (int i=0;i<list.getLength();i++){
                	
       	       	 Node node1 = list.item(i);
       	       	
       	         System.out.println("* Processing Level 1: item: " + Integer.toString(i));
       	         short node1Type = node1.getNodeType();
       	         if ( node1Type == Node.ELEMENT_NODE ) {
       	        	 System.out.println("* Element: " + node1.getNodeName() );
       	         }
       	         if ( node1.hasChildNodes() ) {
       	        	 NodeList level2List = node1.getChildNodes();
       	          if(level2List!=null &&level2List.getLength()>0){
       	        	 for ( int j = 0; j < level2List.getLength(); j++ ) {
       	        		 Node node2 = level2List.item(j);
       	        		 System.out.println("* Processing Level 2: item: " + Integer.toString(i));
       	    	         short node2Type = node2.getNodeType();
       	    	         if ( node2Type == Node.ELEMENT_NODE ) {
       	    	        	 System.out.println("* Element: " + node2.getNodeName() );
       	    	          System.out.println("Name: "
                                  + level2List.item(0).getChildNodes().item(0)
                                          .getNodeValue());
       	    	         }
       	    	         if ( node2.hasChildNodes() ) {
       	    	        	 NodeList level3List = node2.getChildNodes();
       	    	          if(level3List!=null &&level3List.getLength()>0){
       	    	        	 for ( int k = 0; j < level3List.getLength(); k++ ) {
       	    	        		 Node node3 = level2List.item(k);
       	    	        		 System.out.println("* Processing Level 3: item: " + Integer.toString(k));
       	    	    	         short node3Type = node3.getNodeType();
       	    	    	         if ( node3Type == Node.ELEMENT_NODE ) {
       	    	    	        	 System.out.println("* Element: " + node3.getNodeName() );
       	    	    	        	 System.out.println(": "
       	                                  + level3List.item(0).getChildNodes().item(0)
       	                                          .getNodeValue());
       	    	    	         }
       	    	        	 }
       	    	         }
       	    	         }
       	        	 }
       	         }
       	         }
              
                }
            }
            }
     
            catch (Exception e){
                System.out.println(e.toString());
            }
        }

 

Developer
Posts: 777
Registered: ‎07-21-2012
My Device: 9810
My Carrier: 0

Re: problem is xml parsing

[0.0] *******************************doc****net.rim.device.api.xml.jaxp.DOMDocumentImpl@68ecc420
[0.0] *******************************list****net.rim.device.api.xml.jaxp.DOMNodeListImpl@1a330423
[0.0] CharacteristicValue 27 // it ok//
[0.0] * Processing Level 1: item: 0
[0.0] * Element: CharacteristicValue
[0.0] *************************level2List******5
[0.0] * Processing Level 2: item: 0
[0.0] * Processing Level 2: item: 0
[0.0] * Element: Characteristic
[0.0] *************************level3List******3
[0.0] * Processing Level 3: item: 0
[0.0] * Processing Level 3: item: 1
[0.0] * Element: Characteristic

 

            
           
            try{
                
            	
                DocumentBuilderFactory docBuilderFactory= DocumentBuilderFactory. newInstance(); 
                  
                DocumentBuilder docBuilder= docBuilderFactory.newDocumentBuilder();
                  
               
                FileConnection fc=(FileConnection)Connector.open("file:///SDCard/a.xml");
              InputStream  is=fc.openInputStream();
            doc= docBuilder.parse(is);
            System.out.println("*******************************doc****"+doc);
                doc.getDocumentElement ().normalize ();
                NodeList list=doc.getElementsByTagName("CharacteristicValue");
                System.out.println("*******************************list****"+list);
                System.out
                .println("CharacteristicValue " + list.getLength());
                
               if(list!=null &&list.getLength()>0){
                for (int i=0;i<list.getLength();i++){
                	
       	       	 Node node1 = list.item(i);
       	       	
       	         System.out.println("* Processing Level 1: item: " + Integer.toString(i));
       	         short node1Type = node1.getNodeType();
       	         if ( node1Type == Node.ELEMENT_NODE ) {
       	        	 System.out.println("* Element: " + node1.getNodeName() );
       	         }
       	         if ( node1.hasChildNodes() ) {
       	        	 NodeList level2List = node1.getChildNodes();
       	        	 System.out.println("*************************level2List******"+level2List.getLength());
       	          if(level2List!=null &&level2List.getLength()>0){
       	        	 for ( int j = 0; j < level2List.getLength(); j++ ) {
       	        		 Node node2 = level2List.item(j);
       	        		 System.out.println("* Processing Level 2: item: " + Integer.toString(i));
       	    	         short node2Type = node2.getNodeType();
       	    	         if ( node2Type == Node.ELEMENT_NODE ) {
       	    	        	 System.out.println("* Element: " + node2.getNodeName() );
       	    	        
       	    	         }
       	    	         if ( node2.hasChildNodes() ) {
       	    	        	 NodeList level3List = node2.getChildNodes();
       	    	     	 System.out.println("*************************level3List******"+level3List.getLength());
       	    	          if(level3List!=null &&level3List.getLength()>0){
       	    	        	 for ( int k = 0; j < level3List.getLength(); k++ ) {
       	    	        		 Node node3 = level2List.item(k);
       	    	        		 System.out.println("* Processing Level 3: item: " + Integer.toString(k));
       	    	    	         short node3Type = node3.getNodeType();
       	    	    	         if ( node3Type == Node.ELEMENT_NODE ) {
       	    	    	        	 System.out.println("* Element: " + node3.getNodeName() );
       	    	    	        	 System.out.println(": "
       	                                  + level3List.item(0).getChildNodes().item(0)
       	                                          .getNodeValue());
       	    	    	         }
       	    	        	 }
       	    	         }
       	    	         }
       	        	 }
       	         }
       	         }
              
                }
            }
            }
     
            catch (Exception e){
                System.out.println(e.toString());
            }
        

 

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: problem is xml parsing

OK, so you are finding your Characteristic elements, so you can take it from here. 

 

If you are still having problems, sorry, I think I have done all I can can to lead you towards resolving this yourself. I suggest you think about getting a book or going to some classes.  You can't survive as a programmer by cutting and pasting other people's code, you actually have to understand what you are doing.  And you have to research your problems too - you can't expect other people to lead you. 

Developer
Posts: 777
Registered: ‎07-21-2012
My Device: 9810
My Carrier: 0

Re: problem is xml parsing

Sorry sir