Mikroformate mit JAXB in XML abbilden
Die Informationen von Mikroformaten lassen sich mit JAXB relativ leicht in XML konvertieren:
import java.util.*;import javax.xml.bind.*;import javax.xml.bind.annotation.*;public class MicroformatViaJaxb{ public static void main( String[] args ) throws JAXBException { Microformat mf = new Microformat(); mf.elements.add( new Element( "name", "Christian Ullenboom" ) ); mf.elements.add( new Element( "address", "tutego Allee" ) ); mf.elements.add( new Element( "phone", "2873568956928" ) ); JAXBContext context = JAXBContext.newInstance( Microformat.class ); Marshaller m = context.createMarshaller(); m.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE ); m.marshal( mf, System.out ); }}@XmlRootElement( name = "div" )class Microformat{ @XmlAttribute( name = "class" ) public String key = "person"; @XmlElement( name = "span" ) public List elements = new ArrayList();}class Element{ @XmlAttribute( name = "class" ) public String key; @XmlValue public String value; public Element() { } public Element( String key, String value ) { this.key = key; this.value = value; }}