// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.DefaultHandler;

public class Config {
    public static void main(String[] args) throws FileNotFoundException, IOException, ParserConfigurationException, SAXException {
        // properties
        Properties props = new Properties();
        props.load(new FileInputStream("C:\\config.properties"));
        System.out.println(props.getProperty("iv"));
        System.out.println(props.getProperty("sv"));
        // XML
        Map xmlinfo = new HashMap();
        SAXParserFactory spf = SAXParserFactory.newInstance();
        SAXParser sp = spf.newSAXParser();
        XMLReader xr = sp.getXMLReader();
        xr.setContentHandler(new MySaxParser(xmlinfo));
        xr.parse("C:\\config.xml");
        System.out.println(xmlinfo.get("iv"));
        System.out.println(xmlinfo.get("sv"));
    }
}

class MySaxParser extends DefaultHandler {
    private String key;
    private StringBuffer value = new StringBuffer();
    private Map xmlinfo;
    public MySaxParser(Map xmlinfo) {
        this.xmlinfo = xmlinfo;
    }
    public void characters(char buf[], int offset, int len) throws SAXException {
        value.append(new String(buf, offset, len));
        return;
    }
    public void startElement(String namespaceURI, String localName, String rawName, Attributes atts) throws SAXException {
        key = rawName;
        value = new StringBuffer();
        return;
    }
    public void endElement(String namespaceURI, String localName, String rawName) throws SAXException {
        xmlinfo.put(key, value.toString());
        return;
    }
}
