Android: Sax parsing returns null values and retrieve values in tags of same name

前端 未结 2 413

I have these XML on a URL

 

    
        John&         


        
2条回答
  •  误落风尘
    2020-12-11 00:05

    Also to get the attributes from an element you can use something like this: You get the attributes from the atts Attributes in the startElement method.

    }else if (localName.equals("Phone")){
              this.in_Phone=true;
              int length = atts.getLength();
              System.out.println("length = " + length);
              for(int i = 0; i < length; i++){
                  String name = atts.getQName(i);
                  System.out.println(name);
                  String value = atts.getValue(i);
                  System.out.println(value);
                  if(name.equals("loc")){
                      if(value.equals("home")){
                        this.in_homePhone=true;
                      }else if(value.equals("work")){
                        this.in_workPhone=true;
                      }else if(value.equals("mobile")){
                        this.in_mobilePhone=true;
                     }
    
                  }
              }
        }
    

提交回复
热议问题