Click here to Skip to main content
15,886,578 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi i want to parse xml .here is my xml . please help me .

main xml is
HTML
        <characteristicvalue>
           <characteristic>
              <name>ResourceFacingServiceInstance.PortProfileInstance.UpstreamIsTrellisEnabledCode</name>
           </characteristic>
           <value>true
           </value>
        </characteristicvalue>




<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/ResourceConfigurationMessage" xmlns:re="http://www.ibm.com/xmlns/prod/websphere/fabric/2008/12/telecom/operations/inventory/types/schema/QueryResource" xmlns:v20="http://www.ibm.com/telecom/common/schema/mtosi/v2_0">
         &lt;header&gt;
            <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>
         &lt;/header&gt;
         <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.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>


            <specification>
               <type>Optimized DSL Port</type>
               <category>Logical Resource</category>
            </specification>
         </me:physicalresource>
      </re:queryresourceresponse>
   </soapenv:body>
</soapenv:envelope>


******************************************
Main code in in blackberry is

Java
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("CharacteristicValue");
             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
    
}
Posted
Updated 12-Mar-13 22:43pm
v3

1 solution

Hello,

Your XML does not seems to have a root element. Remove following from your xml.
XML
<characteristicvalue>
     <characteristic>
          <name>ResourceFacingServiceInstance.PortProfileInstance.UpstreamIsTrellisEnabledCode</name>
     </characteristic>
     <value>true</value>
</characteristicvalue>

Regards,
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900