Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.io.FileReader;
import java.util.HashMap;
import java.util.Map;

import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamReader;

public class Main {

    public static void main(String[] args) throws Exception {
        XMLInputFactory xif = XMLInputFactory.newFactory();
        XMLStreamReader xsr = xif.createXMLStreamReader(new FileReader("data.xml"));
        xsr.nextTag(); // advance to Employees tag
        xsr.nextTag(); // advance to first Employer element
        Map<String, String> map = new HashMap<String, String>();
        while (xsr.getLocalName().equals("Employee")) {
            map.put(xsr.getAttributeValue("", "id"), xsr.getElementText());
            xsr.nextTag(); // advance to next Employer element
        }
    }

}