- importjava.io.FileOutputStream;
- @H_301_16@importjavax.xml.bind.JAXBContext; @H_301_16@importjavax.xml.bind.Marshaller; @H_301_16@importjavax.xml.bind.annotation.XmlRootElement; @H_301_16@publicclassJavaToXMLDemo{ @H_301_16@staticvoidmain(String[]args)throwsException{
- JAXBContextcontext=JAXBContext.newInstance(Employee.class);
- Marshallerm=context.createMarshaller();
- m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,true);
- Employeeobject=newEmployee();
- object.setCode("CA");
- object.setName("Cath");
- object.setSalary(300);
- m.marshal(object,System.out);
- }
- }
@XmlRootElement
@H_301_16@classEmployee{
@H_301_16@privateStringcode;
@H_301_16@privateStringname;
@H_301_16@privateintsalary;
@H_301_16@publicStringgetCode(){
@H_301_16@returncode;
@H_301_16@voidsetCode(Stringcode){
@H_301_16@this.code=code;
@H_301_16@publicStringgetName(){
@H_301_16@returnname;
@H_301_16@voidsetName(Stringname){
@H_301_16@this.name=name;
@H_301_16@intgetSalary(){
@H_301_16@returnsalary;
@H_301_16@voidsetSalary(intpopulation){
@H_301_16@this.salary=population;
运行结果:
原文链接:https://www.f2er.com/xml/299966.html
- <?xmlversion="1.0"encoding="UTF-8"standalone="yes"?>
- <employee>
- code>CA</name>Cathsalary>300>