import java.io.*;
import java.util.*;
import javax.xml.parsers.*;
import org.xml.sax.*;
import org.xml.sax.helpers.*;
class MyHandler extends DefaultHandler {
private List<String> values = new ArrayList<String>();
private String currentTag
= ""; if(qName.equals("cons")) {
String value
= attrs.
getValue("cat"); values.add(value);
System.
out.
println(f
(values
)); currentTag = qName;
} else if(qName.equals("tok")) {
String value
= attrs.
getValue("pos"); values.add(value);
currentTag = qName;
}
}
if(qName.equals("cons") || qName.equals("tok")) {
int sz = values.size();
values.remove(sz-1);
System.
out.
println(f
(values
)); }
currentTag = "";
}
@Override public void characters(char[] ch, int start, int length) {
if(currentTag.equals("tok")) {
if(str.
length() > 0) { System.
out.
println(" " + str
); } }
}
private String f
(List
<String
> strs
) { StringBuilder res = new StringBuilder("[");
for(String str
: strs
) { res.
append(str
+ ", "); } int sz = res.length();
if(sz > 2) { res.delete(sz-2, sz); }
res.append("]");
return res.toString();
}
}
public class Main {
public static void main
(String[] args
) { try {
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser parser = factory.newSAXParser();
MyHandler handler = new MyHandler();
ex.printStackTrace();
}
}
}
aW1wb3J0IGphdmEuaW8uKjsKaW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YXgueG1sLnBhcnNlcnMuKjsKaW1wb3J0IG9yZy54bWwuc2F4Lio7CmltcG9ydCBvcmcueG1sLnNheC5oZWxwZXJzLio7CgpjbGFzcyBNeUhhbmRsZXIgZXh0ZW5kcyBEZWZhdWx0SGFuZGxlciB7CiAgICBwcml2YXRlIExpc3Q8U3RyaW5nPiB2YWx1ZXMgPSBuZXcgQXJyYXlMaXN0PFN0cmluZz4oKTsKICAgIHByaXZhdGUgU3RyaW5nIGN1cnJlbnRUYWcgPSAiIjsKICAgIEBPdmVycmlkZSBwdWJsaWMgdm9pZCBzdGFydEVsZW1lbnQoU3RyaW5nIG5hbWVzcGFjZVVSSSwgU3RyaW5nIGxvY2FsTmFtZSwgU3RyaW5nIHFOYW1lLCBBdHRyaWJ1dGVzIGF0dHJzKSB7CiAgICAgICAgaWYocU5hbWUuZXF1YWxzKCJjb25zIikpIHsKICAgICAgICAgICAgU3RyaW5nIHZhbHVlID0gYXR0cnMuZ2V0VmFsdWUoImNhdCIpOwogICAgICAgICAgICB2YWx1ZXMuYWRkKHZhbHVlKTsKICAgICAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKGYodmFsdWVzKSk7CiAgICAgICAgICAgIGN1cnJlbnRUYWcgPSBxTmFtZTsKICAgICAgICB9IGVsc2UgaWYocU5hbWUuZXF1YWxzKCJ0b2siKSkgewogICAgICAgICAgICBTdHJpbmcgdmFsdWUgPSBhdHRycy5nZXRWYWx1ZSgicG9zIik7CiAgICAgICAgICAgIHZhbHVlcy5hZGQodmFsdWUpOwogICAgICAgICAgICBTeXN0ZW0ub3V0LnByaW50KGYodmFsdWVzKSk7CiAgICAgICAgICAgIGN1cnJlbnRUYWcgPSBxTmFtZTsKICAgICAgICB9CiAgICB9CiAgICBAT3ZlcnJpZGUgcHVibGljIHZvaWQgZW5kRWxlbWVudChTdHJpbmcgbmFtZXNwYWNlVVJJLCBTdHJpbmcgbG9jYWxOYW1lLCBTdHJpbmcgcU5hbWUpIHsKICAgICAgICBpZihxTmFtZS5lcXVhbHMoImNvbnMiKSB8fCBxTmFtZS5lcXVhbHMoInRvayIpKSB7CiAgICAgICAgICAgIGludCBzeiA9IHZhbHVlcy5zaXplKCk7CiAgICAgICAgICAgIHZhbHVlcy5yZW1vdmUoc3otMSk7CiAgICAgICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbihmKHZhbHVlcykpOwogICAgICAgIH0KICAgICAgICBjdXJyZW50VGFnID0gIiI7CiAgICB9CiAgICBAT3ZlcnJpZGUgcHVibGljIHZvaWQgY2hhcmFjdGVycyhjaGFyW10gY2gsIGludCBzdGFydCwgaW50IGxlbmd0aCkgewogICAgICAgIGlmKGN1cnJlbnRUYWcuZXF1YWxzKCJ0b2siKSkgewogICAgICAgICAgICBTdHJpbmcg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