public class Book { private String title; private String author; // ... } <?xml version="1.0" encoding="UTF-8"?> <mapping> <class name="com.example.Book"> <bindable>true</bindable> <mapping name="title" get-method="getTitle" set-method="setTitle"> <value name="element-name">title</value> </mapping> <mapping name="author" get-method="getAuthor" set-method="setAuthor"> <value name="element-name">author</value> </mapping> </class> </mapping> IBindingFactory factory = BindingDirectory.getFactory(Book.class); IMarshallingContext context = factory.createMarshallingContext(); context.marshalDocument(book, "UTF-8", null, new FileOutputStream("book.xml")); IUnmarshallingContext context = factory.createUnmarshallingContext(); Book book = (Book) context.unmarshalDocument(new FileInputStream("book.xml"), null);


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