Thread: Parsed Document
View Single Post
  #2 (permalink)  
Old 07-29-2007, 03:53 AM
brianhks brianhks is offline
Senior Member
 
Join Date: Jul 2007
Posts: 134
brianhks will become famous soon enough
You should try it like this
If you implement the ContentHandler interface and use that with your sax parser it works a lot better. Then the following code will get you what you are looking for, I think.

Code:
public void startElement(String uri, String localName, String qName, Attributes attr) throws SAXException { String type = attr.getValue("TYPE"); if (type != null) { if (total.containsKey(type)) { //Java 1.5 autoboxing will take care of this for you int temp = (Integer)total.get(type); total.put(type, new Integer(temp+1)); } else if (!total.containsKey(type)) total.put(type, new Integer(1)); } } public void endDocument() { Iterator i = total.entrySet().iterator(); while (i.hasNext()) { Map.Entry temp = (Map.Entry)i.next(); System.out.println(temp.getKey() + " " + temp.getValue()); } }
Reply With Quote