- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSAXHandler.java
More file actions
Latest commit
37 lines (30 loc) · 1.07 KB
/
Copy pathSAXHandler.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
importorg.xml.sax.helpers.DefaultHandler;
importorg.xml.sax.*;
importjava.util.ArrayList;
publicclassSAXHandlerextendsDefaultHandler {
privateStringBuildertext = newStringBuilder();
privateStringname;
privateMusicStorestore;
ArrayList<MusicStore> musicStores = newArrayList<>();
DefaultHandlerhandler = newDefaultHandler() {
publicvoidstartElement(Stringu, Stringm, Stringn, Attributesa) {
if ("store".equals(n)) {
if (store != null) musicStores.add(store);
name = a.getValue("name");
store = newMusicStore(name);
}
if ("instrument".equals(n)) {
Instrumentnewinst = newInstrument(a.getValue("class"),a.getValue("type"), a.getValue("firm"), a.getValue("name"));
store.add_instrum(newinst);
}
}
publicvoidendDocument(){
musicStores.add(store);
}
};
publicvoidprint(){
for(MusicStorestore : musicStores){
store.print();
}
}
}