您的位置:首页 > 编程语言 > Java开发

java解析XML文件-DOM解析法与SAX解析法

2016-07-30 10:46 363 查看
(1)DOM解析法
1.在src下创建class.xml文件
[code=xml;toolbar:false"><class classId="a10">
  <student stuId="1">
     <name>张三</name>
     <sex>女</sex>
     <age>20</age>
  </student>
  <student stuId="2">
     <name>李四</name>
     <sex>男</sex>
     <age>19</age>
  </student>
  <student stuId="3">
     <name>王五</name>
     <sex>男</sex>
     <age>21</age>
  </student>
</class>public class Student {
 private String stuid;
 private int age;
 private double height;
 private String name;
 private String tel;
 private String email1;
 private String email2;
 private String unit;
 private String addressu;
 private String emailu;
 private String company;
 
public String getCompany() {
return company;
}
public void setCompany(String company) {
this.company = company;
}
public String getStuid() {
return stuid;
}
public void setStuid(String stuid) {
this.stuid = stuid;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public double getHeight() {
return height;
}
public void setHeight(double height) {
this.height = height;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getTel() {
return tel;
}
public void setTel(String tel) {
this.tel = tel;
}
public String getEmail1() {
return email1;
}
public void setEmail1(String email1) {
this.email1 = email1;
}
public String getEmail2() {
return email2;
}
public void setEmail2(String email2) {
this.email2 = email2;
}
public String getUnit() {
return unit;
}
public void setUnit(String unit) {
this.unit = unit;
}
public String getAddressu() {
return addressu;
}
public void setAddressu(String addressu) {
this.addressu = addressu;
}
public String getEmailu() {
return emailu;
}
public void setEmailu(String emailu) {
this.emailu = emailu;
}
}<book>
  <title>Java实例一百例</title>
  <page id="1">
    <title>基础知识篇</title>
    <file>base.htm</file>
  </page>
  <page id="3">
    <title>SWING篇</title>
    <file>swing.htm</file>
  </page>
  <page id="28">
    <title>EJB篇</title>
    <file>ejb.htm</file>
  </page>
  <page id="33">
    <title>DOM篇</title>
    <file>xmldom.htm</file>
  </page>
</book>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: