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>
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>
相关文章推荐
- Java 基本语法
- Java 运行环境的安装、配置与运行
- Servlet生命周期
- spring ext 跨域
- Java利用PropertyDescriptor获取属性的 getter/setter 方法
- Struts2 return JSON data and convert the date field
- Spring4笔记----为什么要使用AOP
- 设计模式之禅
- Eclipse下的Android工程改名
- Java枚举类型(二)
- Java语言学习中
- 一步一步解析java集合框架LinkedList源码(3)
- 第十六章 Lambda与Java8
- Java枚举类型(一)
- Spring控制反转与依赖注入
- spring线程池ThreadPoolTaskExecutor与阻塞队列BlockingQueue
- 在dos下运行java jar包,并把命令村为bat文件
- SpringMVC+MyBatis - 7 Spring自动扫描注解类的冲突问题
- IO流切割文件
- Java8 lambda表达式10个示例