JBindXML绑定框架
JBind 框架根据XML Schema生成 Java 绑定代码,构建前端访问存储在XML文档里的数据。
示例代码
package org.jbind.example.meansOfTransport;
import org.jbind.xml.core.data.IDataContext;
import org.jbind.xml.instance.builder.DataContext;
import org.jbind.xml.facade.JBindFacade;
import org.jbind.xml.msg.XmlException;
import java.util.Iterator;
public class Main {
public static void main(String[] args) {
// Create a shared data context
IDataContext context = new DataContext(true);
try {
// Read manufacturers
JBindFacade.unmarshal(Main.class.getResource("manufacturers.xml"), context);
// Read means of transports
IMeansOfTransportsData data = (IMeansOfTransportsData)
JBindFacade.unmarshal(Main.class.getResource("meansOfTransports.xml"), context);
for (Iterator i = data.iterMeansOfTransports(); i.hasNext(); ) {
IMeansOfTransport mot = (IMeansOfTransport)i.next();
IManufacturerData man = mot.refManufacturer();
System.out.println("MeansOfTransport was manufactured by: " + man.getName());
}
} catch (XmlException e) {
e.printStackTrace();
System.exit(-1);
}
System.exit(0);
}
}
评论