package blatt5;

import java.io.*;
import java.util.HashSet;
import java.util.Set;

import javax.xml.stream.*;

public class StaxCountTags 
{	
	Set<String> result;
	
	public void count(String file, Set<String> result) throws IOException
	{
		
	try
	{
	XMLInputFactory factory = XMLInputFactory.newInstance();
	XMLStreamReader parser = factory.createXMLStreamReader(new FileInputStream(file));
	
	{
		while(parser.hasNext()) 
		{    
			int eventType = parser.next();

		    if(eventType == XMLStreamReader.START_ELEMENT)
		    {
		    	result.add(parser.getLocalName());
		    	parser.next();
		    }
		    
		    else if(eventType == XMLStreamConstants.END_DOCUMENT)
		    {
		      System.out.println("Das Dokument enthaelt "+result.size()+" unterschiedliche Tags!");
		      parser.close();	     
	        } 
	}
	}
	}
	catch(XMLStreamException e)
	{
		e.printStackTrace();
	} 
	catch (FileNotFoundException e) 
	{
		e.printStackTrace();
	}
}
	
	public static void main(String args[]) throws IOException
	{
		String file="Skript.xml";
		Set<String> result = new HashSet<String>();
		StaxCountTags sc = new StaxCountTags();
		sc.count(file, result);
	}
}


