JBindXML绑定框架

联合创作 · 2023-09-23 11:07

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);
}
}
浏览 8
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报