相关疑难解决方法(0)

枚举与架构:jaxb或xsd的问题不匹配?

我正在尝试使用JAXB 将此文件解组为Java对象.我知道J6中的SAX存在一个问题,即拒绝maxOccurs线,我已将其更改为unbounded.但是,当我xjc这样做时,它并没有创建我需要的所有类和枚举.例如,应该有一个educationLevelType枚举.更重要的是,我尝试了MS的xsd unmarshaller,它正确地创造了一切.

有经验的人比我看这个并且告诉我我缺少的东西吗?是否需要在xsd中更正某些内容,或者JAXB中是否存在错误?

根据要求,更新 Blaise完全回答了这个问题.不幸的是,恕我直言,这使得JAXB毫无价值.整个想法是我可以从模式生成类 - 我不应该事先知道结构的东西.如果我必须创建一个自定义绑定文件,我不妨创建一个生成我想要的代码的模式.但那么,为什么要停在那里?为什么不跳过所有这些步骤并生成我想要的类?

最后,一位同事向我指出了Apache XMLBeans--该项目有点旧,但它创建的对象没有任何问题.Codehaus还有一个xmlbeans-maven-plugin.

enums jaxb unmarshalling

5
推荐指数
2
解决办法
7164
查看次数

jaxb不生成带有基本整数的枚举

我有以下xsd:

<xs:simpleType name="resultcode">
    <xs:restriction base="xs:integer">
        <xs:enumeration value="0" id="Approved_no_error">
            <xs:annotation>
                <xs:appinfo>
                    <jxb:typesafeEnumMember name="Approved_no_error"/>
                </xs:appinfo>
            </xs:annotation>
        </xs:enumeration>
Run Code Online (Sandbox Code Playgroud)

JAX-B什么都不做,没有错误,没有警告只是不生成这个类.如果改变基数xs:integer,xs:string则可以.但我需要完整的整数值.

我用maven生成类:

<groupId>org.codehaus.mojo</groupId>
    <artifactId>jaxb2-maven-plugin</artifactId>
    <version>1.3</version>
    <executions>
        <execution>
            <id>AuthGateway</id>
            <goals>
                <goal>xjc</goal>
            </goals>
Run Code Online (Sandbox Code Playgroud)

问题2. JAX-B和IDE(IDEA)不允许id attrribute中的空格.为什么?

<xs:enumeration value="0" id="Approved_no_error">- 好的
<xs:enumeration value="0" id="Approved no error">- 不行

这是正确的行为吗?

java xsd jaxb maven

5
推荐指数
1
解决办法
5610
查看次数

标签 统计

jaxb ×2

enums ×1

java ×1

maven ×1

unmarshalling ×1

xsd ×1