如何解析xml,介于两者之间 [英] how to parse xml , struck in between

查看:74
本文介绍了如何解析xml,介于两者之间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我要解析xml。我的xml是。请帮帮我。



主要xml是

Hi i want to parse xml .here is my xml . please help me .

main xml is

        <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

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
    
}

推荐答案

Hello,



Your XML does not seems to have a root element. Remove following from your xml.

Hello,

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



Regards,


Regards,


这篇关于如何解析xml,介于两者之间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆