How to parse xml using different parent nodes in android

前端 未结 1 606
Happy的楠姐
Happy的楠姐 2021-01-27 08:19

In my xml file I have two or more parent nodes like:-

//parent node pizza //attributes are 1 Veg Pizza
//parent node burger

1条回答
  •  伪装坚强ぢ
    2021-01-27 08:43

    carrier.xml ile contains below xml contents
    
    
        
            
            
       
    

    // In your code 
    XmlPullParser xpp=null;
    int eventType = 0;
    XmlPullParserFactory factory =null;
    BufferedReader bufr=null;   
    StringBuilder total ="";
         try{           
        bufr = new BufferedReader(new FileReader("/carrier.xml"));
        total = new StringBuilder();
        String line=""; 
        while ((line = bufr.readLine()) != null)
        {     
        total.append(line);
        }                       
        factory = XmlPullParserFactory.newInstance();  
        factory.setNamespaceAware(true);   
        xpp = factory.newPullParser();   
        xpp.setInput(new StringReader(new String(total)));                  
        eventType = xpp.getEventType();             
        }catch(XmlPullParserException e){
        // Log.v("xmlpullparser"," "+e);
        e.printStackTrace();
        }catch(IOException ie){
        // Log.v("IOException"," "+ie);
        ie.printStackTrace();
        }
    
    
        try{
        while (eventType != XmlPullParser.END_DOCUMENT){                    
        if(eventType == XmlPullParser.START_TAG){ 
        String Scid="",Scname="";
        int acount=xpp.getAttributeCount();             
        if(acount!=-1){
        for(int x=0;x

    0 讨论(0)
提交回复
热议问题