shell java org.jibx.schema.codegen.CodeGen -p com.example.model -t src/main/java/schema.xsd public class Person { @org.jibx.runtime.BindingAlias("name") private String fullName; } <binding> <mapping> <class name="com.example.model.Person"> <field name="fullName" usage="optional" style="element"> <structure name="name" mapping="text"/> </field> </class> </mapping> </binding> IBindingFactory factory = BindingDirectory.getFactory(Person.class); IMarshallingContext mctx = factory.createMarshallingContext(); mctx.setIndent(2); StringWriter writer = new StringWriter(); mctx.marshalDocument(person, "UTF-8", null, writer); IBindingFactory factory = BindingDirectory.getFactory(Person.class); IUnmarshallingContext uctx = factory.createUnmarshallingContext(); FileReader reader = new FileReader("input.xml"); Person person = (Person) uctx.unmarshalDocument(reader, null);


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