51,397
社区成员




package com.hch.testjibx;
import java.io.*;
import org.jibx.runtime.BindingDirectory;
import org.jibx.runtime.IBindingFactory;
import org.jibx.runtime.IMarshallingContext;
import org.jibx.runtime.IUnmarshallingContext;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try{
IBindingFactory bfact = BindingDirectory.getFactory(TeleCustomer.class);
// unmarshal customer information from file
IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
File dataFile = new File("E:\\jbossvss\\testjibx\\classes\\data.xml");
System.out.println("filepath:"+dataFile.getAbsolutePath());
InputStream in = new FileInputStream(dataFile);
FileInputStream testfile=new FileInputStream("E:\\jbossvss\\testjibx\\classes\\data.xml");
InputStreamReader i=new InputStreamReader(testfile,"GBK");
TeleCustomer customer = (TeleCustomer)uctx.unmarshalDocument(in, null);
TeleCustomer customer1 = (TeleCustomer)uctx.unmarshalDocument(i, null);
IMarshallingContext ctx = bfact.createMarshallingContext();
ByteArrayOutputStream os = new ByteArrayOutputStream();
ctx.marshalDocument(customer1, "UTF-8", null,os);
//xstr = new String(os.toString().getBytes("GBK"),"GBK");
System.out.println(new String(os.toString().getBytes("GBK"),"UTF-8"));
System.out.println("customer.phone:"+customer.getPhone());
System.out.println("customer1.phone:"+customer1.getPhone());
System.out.println("customer.addressName:"+customer.getAddress().getAddressName());
System.out.println("customer1.addressName:"+customer1.getAddress().getAddressName());
}catch(Exception e){
e.printStackTrace();
}
}
}