xjc -d src/main/java -p com.example.model xsd/schema.xsd File xmlFile = new File("data.xml"); JAXBContext jaxbContext = JAXBContext.newInstance(Employee.class); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); Employee employee = (Employee) unmarshaller.unmarshal(xmlFile); Employee employee = new Employee("John Doe", 35, "Engineering"); JAXBContext jaxbContext = JAXBContext.newInstance(Employee.class); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(employee, new File("data.xml"));


上一篇:
下一篇:
切换中文