Digester is not an XML Parser, it simply uses digester to encapsulate a higher level of sax, mapping XML to JavaBean. We don't need to understand the parsing process of sax and Dom, as long as we add some parsing rules to digester, we can parse an XML file. Digester uses the stack to hold the XML node (Stack.push () method), which is ejected (Stack.pup () method) when all child nodes nested in the XML node are resolved. The biggest advantage of Digester is the use of pattern matching to represent the parent-child relationship between nodes in an XML file.
The code is as follows:
Students.xml
<?xml version="1.0" encoding="UTF-8" ?>
<stuClass name="fddfdf">
<student>
<name from="cn">Java Boy</name>
<course>JSP</course>
</student>
<student>
<name>Java Girl</name>
<course>EJB</course>
</student>
</stuClass>
Model class: Student.java
package demo.javabean;
public class Student ...{
private String name;
private String from;
private String course;
public String getName() ...{
return name;
}
public void setName(String name) ...{
this.name = name;
}
public String getFrom() ...{
return from;
}
public void setFrom(String from) ...{
this.from = from;
}
public String getCourse() ...{
return course;
}
public void setCourse(String course) ...{
this.course = course;
}
}