xmlpull 解析xml

     private static void readXmlFile()
 {
     XmlPullParser parser=Xml.newPullParser();
     try{
     File file = new File("/data/data/com.excel.dansport/shared_prefs/ServiceIp.xml");
     FileInputStream fileIn=new FileInputStream(file);
     parser.setInput(fileIn, "UTF-8");
     int eventType=parser.getEventType();
     while(eventType!=XmlPullParser.END_DOCUMENT)
     {
      String nodeName = parser.getName();
      
      switch (eventType) {
   case XmlPullParser.START_DOCUMENT:
    System.out.println("开始START_DOCUMENT"+nodeName);
    break;
    
   case XmlPullParser.START_TAG:
    System.out.println("START_TAG"+nodeName);
    
     if("string".equals(parser.getName())){
               String tag=parser.getAttributeValue(0);
            if((tag!=null)&&tag.equals("LocalIp"))
            {
             //LOCAL_URL=(String)parser.nextText();
             System.out.println(parser.nextText());
                  
            }else if((tag!=null)&&tag.equals("Ip")){
             //ROOT_URL=(String)parser.nextText();
             System.out.println(parser.nextText());
            }
              }
    
    break; 
    
   case XmlPullParser.END_TAG:
    System.out.println("END_TAG"+nodeName);
   break; 
   
   case XmlPullParser.END_DOCUMENT:
    System.out.println("END_TAG"+nodeName);
   break;
   
   default:
    break;
   }
            eventType=parser.next();
        
        
     }
//     }catch(XmlPullParserException e)
//     {
//       Log.e("CutomHttpClient.readXmlFile", ClientUtil.exceptionToString(e));
     }
     catch(Exception e)
     {
      Log.e("CutomHttpClient.readXmlFile", ClientUtil.exceptionToString(e));
     }
 }

你可能感兴趣的:(xmlpull 解析xml)