Thread: Parsed Document
View Single Post
  #1 (permalink)  
Old 07-28-2007, 07:09 PM
nick211001 nick211001 is offline
Member
 
Join Date: Jul 2007
Posts: 1
nick211001 is on a distinguished road
Parsed Document
Hi,

I have developed the following method which extracts data from a saxed XML document:


public void startElement(String elementName, AttributeList al) throws SAXException
{
//Executed when a start element is encountered
//elementName contains the name of the element and al contains
//a list of the attributes
String attributeName, attributeValue;
if(al.getLength()>0)//iteration process through the parsed document
for(int j = 0;j<al.getLength();j++)

{
attributeName = al.getName(j);
attributeValue = al.getValue(j);
{
if (attributeName.equals("TYPE"))
if (total.containsKey(attributeValue)) {
Integer temp = (Integer)total.get(attributeValue);
int temp2 = temp.intValue();
total.put(attributeValue, new Integer(temp2+1));
}
else if (!total.containsKey(attributeValue))
total.put(attributeValue, new Integer(1));
}
}
Iterator i = total.entrySet().iterator();
while (i.hasNext()) {
Map.Entry temp = (Map.Entry)i.next();
System.out.println(temp.getKey() + " " + temp.getValue());
}


This iterates through the parsed document and appears to run the method each time a "TYPE" (XML extract <FILE TYPE = "Word">) attribute is encounted.

Can anyone tell me how to stop it continually iterating since I only need it to present the final totals ie. Word Files = 3, Excel Files = 2 etc.
Reply With Quote
Sponsored Links