
{filelink=8748}
/***** Code de MesExemples.com *******/
import javax.xml.bind.JAXBContext;import javax.xml.bind.JAXBException;import javax.xml.bind.Marshaller;import javax.xml.bind.annotation.XmlRootElement;@XmlRootElement(name = "person", namespace = "http://www.example.com/myperson")public class MyPerson { private String first; private String last; public static void main(String[] args) throws JAXBException { MyPerson p = new MyPerson(); p.first = "l"; p.last = "h"; JAXBContext context = JAXBContext.newInstance(MyPerson.class); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(p, System.out); } public String getFirst() { return first; } public void setFirst(String first) { this.first = first; } public String getLast() { return last; } public void setLast(String last) { this.last = last; }} |
Code testé avec le fichier XML Suivant
<?xml version="1.0" encoding="windows-1252"?>
<!-- Edited by MesEXemple.com -->
<note>
<to>Sakoba</to>
<from>Adams</from>
<heading>Rappel</heading>
<body>Ne m'oubliez pas ce week-end!</body>
</note> |
A Voir sur le même Sujet:
- programme java exemple
- programmer un menu et sous menu imbriquées