java enum 多个字段_java – 如何使用允许jibx中的多个枚举值的...

我想使用Jibx来解组以下XML(存储在名为test.xml的文件中):

我定义了模式(在一个名为simple.xsd的文件中),如下所示:

使用org.jibx.schema.codegen.CodeGen工具从中生成Java文件并编写此测试程序:

package test;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import org.jibx.runtime.BindingDirectory;

import org.jibx.runtime.IBindingFactory;

import org.jibx.runtime.IUnmarshallingContext;

import org.jibx.runtime.JiBXException;

import my.target.ns.RootElement;

public final class Program {

public static void main(final String[] args) {

try {

IBindingFactory bfact = BindingDirectory.getFactory(RootElement.class);

IUnmarshallingContext uctx = bfact.createUnmarshallingContext();

FileInputStream in = new FileInputStream(new File("test.xml"));

RootElement data = (RootElement) uctx.unmarshalDocument(in, null);

// This is not what I was expecting. I was expecting

// List (or equivalent) not

// a single RootElement.Enumeration instance

RootElement.Enumeration attrValue = data.getAttrWithEnum();

System.out.println(attrValue);

} catch (Exception e) {

System.out.println(e.toString());

}

}

}

该程序失败并显示错误:

org.jibx.runtime.JiBXException: No match found for value ‘avalue anothervalue’ in enum class my.target.ns.RootElement$Enumeration

如果我像这样调整我的输入XML(即只设置一个枚举值)它可以工作(打印AVALUE).

所以,似乎jibx不喜欢我想要允许枚举值列表(我希望getAttrWithEnum返回一个集合,但它返回一个对象 – 请参阅上面代码示例中的注释).

当我使用jaxb(使用xjc生成java文件)时,相同的XSD工作正常,所以我认为我的XSD是有效的(尽管如果有更好的方法来定义我想要的东西,那就没问题).

因此,我的问题是:

如何使用允许jibx中的多个枚举值的属性来解组XML文档?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值