// 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.beans.XMLEncoder;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;

public class Object2Xml {
    public static void main(String[] args) throws Exception {
        Foobar o = new Foobar(123, 123.456, "ABC");
        // oldfashioned
        XMLEncoder xe = new XMLEncoder(System.out);
        xe.writeObject(o);
        xe.flush();
        // modern
        JAXBContext jxbctx = JAXBContext.newInstance(Foobar.class);
        Marshaller m = jxbctx.createMarshaller();
        m.marshal(o, System.out);
    }
}
