1、基本原理:
常用的有:
XmlPullParser.END_DOCUMENT
XmlPullParser.START_DOCUMENT
XmlPullParser.START_TAG
XmlPullParser.END_TAG
XmlPullParser.TEXT 
分别代表着XML文档的结束,开始,标签的开始,标签的结束,内容 

按照以上的格式依次进行解析即可。

2、介绍了三种不同的xml格式及解析方法

新建一个新的activiy文件,其实就是程序启动发源地而已。

 

<span style="font-size: 18px;">public class MainActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);       
        xmltest xl = new xmltest();
        xl.test(getResources());
    }
   }</span>

 

 

为了便于xml解析内容的存取,新建了一个Person.java类,内容如下:

 

package com.test.xmlactivity;
class Person{
    private int id = -1;
    private int age = 0;
    private String name = null;
    private String title = null;
                                                                                                                                    
    public Person(){
        //TODO
    }
                                                                                                                                    
    public Person(int _id,int _age,String _name,String _title){
        this.id = _id ;
        this.age = _id;
        this.name = _name;
        this.title = _title;
    }
                                                                                                                                    
    public void setID(int id){
        this.id = id;
    }
                                                                                                                                    
    public int getID(){
        return this.id;
    }
                                                                                                                                    
    public void setAge(int age){
        this.age = age;
    }
                                                                                                                                    
    public int getAge(){
        return this.age;
    }
                                                                                                                                    
    public void setName(String name){
        this.name = name;
    }
                                                                                                                                    
    public String getName(){
        return this.name;
    }
                                                                                                                                    
    public void setTitle(String title){
        this.title = title;
    }
                                                                                                                                    
    public String getTitle(){
        return this.title;
    }
};
View Code

相关文章:

  • 2021-12-28
  • 2021-04-13
  • 2021-09-05
  • 2021-10-18
  • 2022-01-09
  • 2022-12-23
  • 2021-12-04
  • 2021-07-02
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-24
  • 2021-05-20
  • 2022-12-23
  • 2022-01-03
相关资源
相似解决方案