Source Code : Mark a POJO with XmlRootElement with name and namespace
Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com.
Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com.
Click Here or search from google with Libraries Name you get jar file related it
Mark a POJO with XmlRootElement with name and namespace
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;
}
}
Thank with us