// Collection of code snippets by Arne Vajhøj 
// (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.List;

import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;

public class ParseJDOMSAX {
    private final static String XML_FILE = "C:\\test.xml";
    public static void main(String[] args) {
        try {
            SAXBuilder b = new SAXBuilder();
            Document doc = b.build(new FileReader(XML_FILE));
            List list = doc.getRootElement().getChildren();
            for (int i = 0; i < list.size(); i++) {
                Element elm = (Element) list.get(i);
                String no = elm.getAttributeValue("no");
                String name = elm.getChild("navn").getText();
                String address = elm.getChild("adresse").getText();
                System.out.println("no=" + no);
                System.out.println("navn=" + name);
                System.out.println("adresse=" + address);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (JDOMException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
