今天我们来聊聊SAX方式解析、生成XML文档
SAX介绍:
1、SAX方式解析XML
1、具体流程
2、实现思路
3、要解析的acc.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<accounts>
<account age="25" bankNo="acc1003">
<id>610105200210102233</id>
<name>小王</name>
<money>6000.0</money>
</account>
</accounts>
4、与xml的实体类Account.java
package com.yueqian.xml;
/**
* 封装xml的实体类
* @author LinChi
*
*/
public class Account {
private String bankNo;
private int age;
private String id;
private String name;
private double money;
public Account() {
super();
}
public Account(String bankNo, int age, String id, String name, double money) {
super();
this.bankNo = bankNo;
this.age = age;
this.id = id;
this.name = name;
this.money = money;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getMoney() {
return money;
}
public void setMoney(double money) {
this.money = money;
}
public String getBankNo() {
return bankNo;
}
public void setBankNo(String bankNo) {
this.bankNo = bankNo;
}
@Override
public String toString() {
return this.bankNo+"|"+this.age+"|"+this.id+"|"+this.name+"|"+this.money;
}
}
5、定义事件监听器
pa