import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamException;

public class CursorSample1 {
    public CursorSample1(String xmlfile) {
        // 1. パーサ用ファクトリの生成
        XMLInputFactory factory = XMLInputFactory.newInstance();
       
        XMLStreamReader reader = null;
        BufferedInputStream stream = null;
        
        try {
            // 2. 入力に使用するファイルの設定
            stream = new BufferedInputStream(
                         new FileInputStream(xmlfile));
            
            // 3. パーサの生成
            reader = factory.createXMLStreamReader(stream);
            
            // 4. イベントループ
            while (reader.hasNext()) {
                // 4.1 次のイベントを取得
                int eventType = reader.next();
                
                // 4.2 イベントが要素の開始であれば、名前を出力する
                if (eventType == XMLStreamReader.START_ELEMENT) {
                    System.out.println("Name: " + reader.getName());
                }
            }
        } catch (FileNotFoundException ex) {
            System.err.println(xmlfile + " が見つかりません");
        } catch (XMLStreamException ex) {
            System.err.println(xmlfile + " の読み込みに失敗しました");
        } finally {
            // 5. パーサ、ストリームのクローズ
            if (reader != null) {
                try {
                    reader.close();
                } catch (XMLStreamException ex) {}
            }
            if (stream != null) {
                try {
                    stream.close();
                } catch (IOException ex) {}
            }
        }
    }
    
    public static void main(String[] args) {
        new CursorSample1(args[0]);
    }
}

