xsi: type = xmlns: xsi = , . ?
, xsi: . , . ?
- , .
, , , @XmlValue. . name DesiredSkill :
import java.util.*;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class Root {
private List<DesiredSkill> employeeDesiredSkills = new ArrayList<DesiredSkill>();
public List<DesiredSkill> getEmployeeDesiredSkills() {
return employeeDesiredSkills;
}
public void setEmployeeDesiredSkills(List<DesiredSkill> employeeDesiredSkills) {
this.employeeDesiredSkills = employeeDesiredSkills;
}
}
import javax.xml.bind.annotation.XmlValue;
public class DesiredSkill {
private String name;
@XmlValue
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
:
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
public class Demo {
public static void main(String[] args) throws Exception {
Root root = new Root();
DesiredSkill cDev = new DesiredSkill();
cDev.setName("C Development");
root.getEmployeeDesiredSkills().add(cDev);
DesiredSkill perlDev = new DesiredSkill();
perlDev.setName("Perl Development");
root.getEmployeeDesiredSkills().add(perlDev);
JAXBContext jc = JAXBContext.newInstance(Root.class);
Marshaller marshaller = jc.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(root, System.out);
}
}
:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<root>
<employeeDesiredSkills>C Development</employeeDesiredSkills>
<employeeDesiredSkills>Perl Development</employeeDesiredSkills>
</root>