-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSAXHandler.java
More file actions
37 lines (30 loc) · 1.07 KB
/
SAXHandler.java
File metadata and controls
37 lines (30 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.*;
import java.util.ArrayList;
public class SAXHandler extends DefaultHandler {
private StringBuilder text = new StringBuilder();
private String name;
private MusicStore store;
ArrayList<MusicStore> musicStores = new ArrayList<>();
DefaultHandler handler = new DefaultHandler() {
public void startElement(String u, String m, String n, Attributes a) {
if ("store".equals(n)) {
if (store != null) musicStores.add(store);
name = a.getValue("name");
store = new MusicStore(name);
}
if ("instrument".equals(n)) {
Instrument newinst = new Instrument(a.getValue("class"),a.getValue("type"), a.getValue("firm"), a.getValue("name"));
store.add_instrum(newinst);
}
}
public void endDocument(){
musicStores.add(store);
}
};
public void print(){
for(MusicStore store : musicStores){
store.print();
}
}
}