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

problem is xml parsing

i want to parse xml . but didnot able to parse .please help me.

my xml is 

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Body>
      <re:queryResourceResponse xmlns:me="http://www.ibm.com/xmlns/prod/websphere/fabric/2008/12/telecom/operations/inventory/schema/ResourceC..." xmlns:re="http://www.ibm.com/xmlns/prod/websphere/fabric/2008/12/telecom/operations/inventory/types/schema/Que..." xmlns:v20="http://www.ibm.com/telecom/common/schema/mtosi/v2_0">
         <header>
            <v20:timestamp>2012-10-15T23:42:26.275Z</v20:timestamp>
            <v20:activityName>QueryResource</v20:activityName>
            <v20:communicationPattern>SimpleResponse</v20:communicationPattern>
            <v20:communicationStyle>MSG</v20:communicationStyle>
            <v20:msgSpecificProperties>
               <v20:property>
                  <v20:propName>DSLe provisioning_infoPortType.getLineInfo</v20:propName>
                  <v20:propValue>SUCCESS</v20:propValue>
               </v20:property>
               <v20:property>
                  <v20:propName>Name: DSLe pe_dataPortType.getData</v20:propName>
                  <v20:propValue>SUCCESS</v20:propValue>
               </v20:property>
               <v20:property>
                  <v20:propName>Instance: DSLe pe_dataPortType.getData</v20:propName>
                  <v20:propValue>SUCCESS</v20:propValue>
               </v20:property>
            </v20:msgSpecificProperties>
         </header>
         <me:physicalResource>
            <CharacteristicValue>
               <Characteristic>
                  <Name>ResourceFacingServiceInstance.PortProfileInstance.UpstreamIsTrellisEnabledCode</Name>
               </Characteristic>
               <Value>true
			   </Value>
            </CharacteristicValue>
            <CharacteristicValue>
               <Characteristic>
                  <Name>ResourceFacingServiceInstance.PortProfileInstance.UpstreamSupportedStandardsNumber</Name>
               </Characteristic>
               <Value>20056</Value>
            </CharacteristicValue>
            <CharacteristicValue>
               <Characteristic>
                  <Name>ResourceFacingServiceInstance.PortProfileInstance.DownstreamMaxMarginNumber</Name>
               </Characteristic>
               <Value>15.0</Value>
            </CharacteristicValue>
            <CharacteristicValue>
               <Characteristic>
                  <Name>ResourceFacingServiceInstance.PortProfileInstance.DownstreamMinMarginNumber</Name>
               </Characteristic>
               <Value>0.0</Value>
            </CharacteristicValue>
            <CharacteristicValue>
               <Characteristic>
                  <Name>ResourceFacingServiceInstance.PortProfileInstance.DownstreamMaxRateNumber</Name>
               </Characteristic>
               <Value>31520</Value>
            </CharacteristicValue>
            <CharacteristicValue>
               <Characteristic>
                  <Name>ResourceFacingServiceInstance.PortProfileInstance.UpstreamINPNumber</Name>
               </Characteristic>
               <Value>2.0</Value>
            </CharacteristicValue>
            <CharacteristicValue>
               <Characteristic>
                  <Name>ResourceFacingServiceInstance.PortProfileInstance.PortProfileName</Name>
               </Characteristic>
               <Value>26-31Mb_16ms_INP_2:8B_12DB</Value>
            </CharacteristicValue>
            <CharacteristicValue>
               <Characteristic>
                  <Name>ResourceFacingServiceInstance.PortProfileInstance.DownstreamMinRateNumber</Name>
               </Characteristic>
               <Value>26240</Value>
            </CharacteristicValue>
            <CharacteristicValue>
               <Characteristic>
                  <Name>ResourceFacingServiceInstance.PortProfileInstance.DownstreamPlanRateNumber</Name>
               </Characteristic>
               <Value>31520</Value>
            </CharacteristicValue>
            <CharacteristicValue>
               <Characteristic>
                  <Name>ResourceFacingServiceInstance.PortProfileInstance.UpstreamMinMarginNumber</Name>
               </Characteristic>
               <Value>0.0</Value>
            </CharacteristicValue>
            <CharacteristicValue>
               <Characteristic>
                  <Name>ResourceFacingServiceInstance.PortProfileInstance.DownstreamMaxPowerNumber</Name>
               </Characteristic>
               <Value>20.4</Value>
            </CharacteristicValue>
            <CharacteristicValue>
               <Characteristic>
                  <Name>ResourceFacingServiceInstance.PortProfileInstance.UpstreamMaxPSDNumber</Name>
               </Characteristic>
               <Value>-38.0</Value>
            </CharacteristicValue>
            <CharacteristicValue>
               <Characteristic>
                  <Name>ResourceFacingServiceInstance.PortProfileInstance.DownstreamInterleavingCode</Name>
               </Characteristic>
               <Value>true</Value>
            </CharacteristicValue>
            <CharacteristicValue>
               <Characteristic>
                  <Name>ResourceFacingServiceInstance.PortProfileInstance.UpstreamMaxRateNumber</Name>
               </Characteristic>
               <Value>3072</Value>
            </CharacteristicValue>
            <CharacteristicValue>
               <Characteristic>
                  <Name>ResourceFacingServiceInstance.PortProfileInstance.DownstreamTargetMarginNumber</Name>
               </Characteristic>
               <Value>12.0</Value>
            </CharacteristicValue>
            <CharacteristicValue>
               <Characteristic>
                  <Name>ResourceFacingServiceInstance.PortProfileInstance.DownstreamIsTrellisEnabledCode</Name>
               </Characteristic>
               <Value>true</Value>
            </CharacteristicValue>
            <CharacteristicValue>
               <Characteristic>
                  <Name>ResourceFacingServiceInstance.PortProfileInstance.DownstreamMaxPSDNumber</Name>
               </Characteristic>
               <Value>-40.0</Value>
            </CharacteristicValue>
            <CharacteristicValue>
               <Characteristic>
                  <Name>ResourceFacingServiceInstance.PortProfileInstance.UpstreamMinRateNumber</Name>
               </Characteristic>
               <Value>128</Value>
            </CharacteristicValue>
            <CharacteristicValue>
               <Characteristic>
                  <Name>ResourceFacingServiceInstance.PortProfileInstance.UpstreamInterleavingCode</Name>
               </Characteristic>
               <Value>true</Value>
            </CharacteristicValue>
            <CharacteristicValue>
               <Characteristic>
                  <Name>ResourceFacingServiceInstance.PortProfileInstance.UpstreamPlanRateNumber</Name>
               </Characteristic>
               <Value>3072</Value>
            </CharacteristicValue>
            <CharacteristicValue>
               <Characteristic>
                  <Name>ResourceFacingServiceInstance.PortProfileInstance.UpstreamMaxPowerNumber</Name>
               </Characteristic>
               <Value>12.5</Value>
            </CharacteristicValue>
            <CharacteristicValue>
               <Characteristic>
                  <Name>ResourceFacingServiceInstance.PortProfileInstance.DownstreamMaxDelayNumber</Name>
               </Characteristic>
               <Value>16.0</Value>
            </CharacteristicValue>
            <CharacteristicValue>
               <Characteristic>
                  <Name>ResourceFacingServiceInstance.PortProfileInstance.UpstreamTargetMarginNumber</Name>
               </Characteristic>
               <Value>12.0</Value>
            </CharacteristicValue>
            <CharacteristicValue>
               <Characteristic>
                  <Name>ResourceFacingServiceInstance.PortProfileInstance.UpstreamMaxDelayNumber</Name>
               </Characteristic>
               <Value>8.0</Value>
            </CharacteristicValue>
            <CharacteristicValue>
               <Characteristic>
                  <Name>ResourceFacingServiceInstance.PortProfileInstance.UpstreamMaxMarginNumber</Name>
               </Characteristic>
               <Value>15.0</Value>
            </CharacteristicValue>
            <CharacteristicValue>
               <Characteristic>
                  <Name>ResourceFacingServiceInstance.PortProfileInstance.DownstreamINPNumber</Name>
               </Characteristic>
               <Value>2.0</Value>
            </CharacteristicValue>
            <CharacteristicValue>
               <Characteristic>
                  <Name>ResourceFacingServiceInstance.PortProfileInstance.DownstreamSupportedStandardsNumber</Name>
               </Characteristic>
               <Value>20056</Value>
            </CharacteristicValue>
            <Specification>
               <Type>Optimized DSL Port</Type>
               <Category>Logical Resource</Category>
            </Specification>
         </me:physicalResource>
      </re:queryResourceResponse>
   </soapenv:Body>
</soapenv:Envelope>

 

 

and my code is like this

 

package mypackage;

import java.io.IOException;
import java.io.InputStream;

import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import javax.microedition.io.StreamConnection;
import javax.microedition.io.file.FileConnection;

import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import net.rim.device.api.io.File;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.xml.parsers.DocumentBuilder;
import net.rim.device.api.xml.parsers.DocumentBuilderFactory;

/**
 * A class extending the MainScreen class, which provides default standard
 * behavior for BlackBerry GUI applications.
 */
public final class MyScreen extends MainScreen
{
    /**
     * Creates a new MyScreen object
     */
	 Document doc;
     StreamConnection conn;
     HttpConnection hc = null;
     FileConnection fc=null;
    public MyScreen()
    {        
    	Connection  _connectionthread = new Connection();
        _connectionthread.start();
    	
  	 
		
	
     
    }
    
    private class Connection extends Thread
    {
        public Connection(){
            super();
        }

        public void run()
        {
            
           
            try{
                
            	//Dialog.alert("hai");
               
            	
                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);
                doc.getDocumentElement ().normalize ();
                NodeList list=doc.getElementsByTagName("Characteristic");
             String   _node=new String();
             String  _element = new String();
                

                for (int i=0;i<list.getLength();i++){
                    Node value=list.item(i).
                      getChildNodes().item(0);
                    _node=list.item(i).getNodeName();
                    _element=value.getNodeValue();
                System.out.println("*****************_node+ value"+_node+_element);
                }//end for
            }//end try
            //will catch any exception thrown by the XML parser
            catch (Exception e){
                System.out.println(e.toString());
            }
        }//end connection function
    }// end connection class
    
}

 

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

Re: problem is xml parsing

And your problem is????????

 

The search facility is always a good place to start:

http://supportforums.blackberry.com/t5/Java-Development/Use-the-XML-Parser/ta-p/445210

 

Also this is a SOAP request, so perhaps you need to look at a Soap communication method.  Again search for help with this. 

 

Finally please just ask questions once.  I will ask to have your other similar Thread removed. 

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

Re: problem is xml parsing

  <CharacteristicValue>
               <Characteristic>
                  <Name>ResourceFacingServiceInstance.PortProfileInstance.UpstreamIsTrellisEnabledCode</Name>
               </Characteristic>
               <Value>true
               </Value>
            </CharacteristicValue>

 

I want to print all name and value which is in inserted in the CharacteristicValue.

Please so some help

 

private class Connection extends Thread
    {
        public Connection(){
            super();
        }

        public void run()
        {
            
           
            try{
                
                //Dialog.alert("hai");
               
                
                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);
             String   _node=new String();
             String  _element = new String();
                

                for (int i=0;i<list.getLength();i++){
                     Node node = list.item(i);
                     System.out.println("**************Node"+node);
                     NamedNodeMap map = node.getAttributes();
                     for (int j = 0; j < map.getLength(); j++) {
                         Node name = map.getNamedItem("Characteristic");
                         System.out.println("Name"+name);
                     }
                    Node textNode = list.item(i).getFirstChild();
                System.out.println("*******************************textNode****"+textNode);
                
                System.out.println("*******************************textNode.getNodeValue()****"+textNode.getNodeValue());
                    Node value=list.item(i).
                      getChildNodes().item(0);
                    _node=list.item(i).getNodeName();
                    _element=value.getNodeValue();
                System.out.println("*****************_node+ value"+_node+_element);
                }//end for
            }//end try
            //will catch any exception thrown by the XML parser
            catch (Exception e){
                System.out.println(e.toString());
            }
        }//end connection function
    }// end connection class
    
}

 

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

Re: problem is xml parsing

And your problem is?

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

Re: problem is xml parsing

Error is nothing . But there is problem in parsing ..

I am not able to do properly , can you help me help in doing nexted tag?

 

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

Re: problem is xml parsing

Sorry I can't say what is wrong from the information given.  I think you can give us a lot more information and I don't understand why you have not - remember the more information you give us the better our answers will be. 

 

In this case information that you should have given us includes which output entries you see, what happens when you step through the code, what exceptions you see, and what happens when you try different input. 

 

From the information I have seen the most likely problem is that you don't have an SD Card input file but that is just a guess and you should have already checked that was not the problem by yourself - say by checking the length of data available from the file connection.  

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

Re: problem is xml parsing

Hello sir i will give you more information.I am making one test project, where i save one xml file(attached one ) in SDcard .

 

I want to show all name and value in that xml. So i have to parse that xml .so i have to iterate using loop whole xml .

 

First i have  <meSmiley TonguehysicalResource> this tag in this i have 27  <CharacteristicValue> this tag .In  <CharacteristicValue> there is two tag  <Characteristic> and   <Value>. In  <Characteristic> there is <Name> tag.

 

I need value  of <Name>  and <Value> tag.

 

Thanks

 

 

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

Re: problem is xml parsing

Let us start simple.  In your code yuou have a number of System.out.println statements.  What does the debugging output log show you for these?

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

Re: problem is xml parsing

package mypackage;

import java.io.InputStream;

import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import javax.microedition.io.StreamConnection;
import javax.microedition.io.file.FileConnection;

import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.xml.parsers.DocumentBuilder;
import net.rim.device.api.xml.parsers.DocumentBuilderFactory;

/**
 * A class extending the MainScreen class, which provides default standard
 * behavior for BlackBerry GUI applications.
 */
public final class MyScreen extends MainScreen
{
    /**
     * Creates a new MyScreen object
     */
	 Document doc;
     StreamConnection conn;
     HttpConnection hc = null;
     FileConnection fc=null;
    public MyScreen()
    {        
    	Connection  _connectionthread = new Connection();
        _connectionthread.start();
    	
  	 
    }
    
    private class Connection extends Thread
    {
        public Connection(){
            super();
        }

        public void run()
        {
            
           
            try{
                
            	//Dialog.alert("hai");
               
            	
                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); //output [0.0] *******************************doc****net.rim.device.api.xml.jaxp.DOMDocumentImpl@5b00b49a 
                doc.getDocumentElement ().normalize ();
                NodeList list=doc.getElementsByTagName("CharacteristicValue");
                System.out.println("*******************************list****"+list);//output *******************************list****net.rim.device.api.xml.jaxp.DOMNodeListImpl@84cbdade
             String   _node=new String();
             String  _element = new String();
                

                for (int i=0;i<list.getLength();i++){
                	 Node node = list.item(i);
                	 System.out.println("**************Node"+node);//output   **************Nodenet.rim.device.api.xml.jaxp.DOMElementImpl@e8c29e11
                	 NamedNodeMap map = node.getAttributes();
                	 for (int j = 0; j < map.getLength(); j++) {
                		 Node name = map.getNamedItem("Characteristic");
                		 System.out.println("Name"+name.getNodeName());
                	 }
                	Node textNode = list.item(i).getFirstChild(); 
                System.out.println("*******************************textNode****"+textNode);//output  *******************************textNode****
                
                System.out.println("*******************************textNode.getNodeValue()****"+textNode.getNodeValue());//output  *******************************textNode.getNodeValue()****
                    Node value=list.item(i).
                      getChildNodes().item(0);
                    _node=list.item(i).getNodeName();
                    _element=value.getNodeValue();
                System.out.println("*****************_node+ value"+_node+_element); //output *****************_node+ valueCharacteristicValue
                }//end for
            }//end try
            //will catch any exception thrown by the XML parser
            catch (Exception e){
                System.out.println(e.toString());
            }
        }//end connection function
    }// end connection class
    
}

 I write output aside with system.println(); please help .from the morning i struck in this problem

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

Re: problem is xml parsing

I think the biggest problem here is that you do not understand XML.  Here is a primer:

https://studio.tellme.com/general/xmlprimer.html

There are many good sources describing XML on the web,  I recommend that you review these. You need to understand things like elements, attributes, and tags.  Then you need to understand how XML elements are grouped together.  Then you need to understand how these elements are processed by the parser, how to extract the attributes associated with an element and how to drill down to get the constituent elements.  So search round and get to understand how an XML document is created. 

 

Once you understand that, I think you will resolve your own problem.

 

The key is what you do when you find a CharacteristicValue value.  It does not have any attributes - it just has child nodes.  Your code does find the CharacteristicValue but will never find the child elements.