xjc mySchema.xsd JAXBContext jaxbContext = JAXBContext.newInstance(MyObject.class); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); MyObject obj = new MyObject(); obj.setName("John"); obj.setAge(30); marshaller.marshal(obj, System.out); JAXBContext jaxbContext = JAXBContext.newInstance(MyObject.class); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); String xmlData = "<myObject><name>John</name><age>30</age></myObject>"; StringReader reader = new StringReader(xmlData); MyObject obj = (MyObject) unmarshaller.unmarshal(reader);


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