Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将xml模式选择元素解组为单独的列表_Java_Jaxb_Xsd_Unmarshalling_Choice - Fatal编程技术网

Java 将xml模式选择元素解组为单独的列表

Java 将xml模式选择元素解组为单独的列表,java,jaxb,xsd,unmarshalling,choice,Java,Jaxb,Xsd,Unmarshalling,Choice,是否可以使用以下模式: <xs:complexType name="GroupType"> <xs:sequence> <xs:choice minOccurs="0" maxOccurs="unbounded"> <xs:element type="PageType" name="Page" minOccurs="0" maxOccurs="unbounded"/>

是否可以使用以下模式:

<xs:complexType name="GroupType">
    <xs:sequence>
        <xs:choice minOccurs="0" maxOccurs="unbounded">
            <xs:element type="PageType" name="Page" minOccurs="0" maxOccurs="unbounded"/>           
            <xs:element type="GroupType" name="Group" minOccurs="0" maxOccurs="unbounded"/>                
            <xs:element type="ResourcesType" name="Resources" minOccurs="0" maxOccurs="1"/>
        </xs:choice>
    </xs:sequence>
</xs:complexType>

..以不同元素类型在单独列表中的方式进行解组? e、 g:

公共类GroupType{
列表页;
列表组;
资源体育资源;
...
}

JAXB的默认行为是将与
选项
匹配的所有元素组合到一个通用列表中。在编组时,我不关心如何排序或重新创建精确的文档,因此更好地组织数据而不是将其作为精确的副本将非常方便。

从POJO开始,您可以如下注释您的类:

@XmlAccessorType(XmlAccessType.FIELD)
public class GroupType {
    @XmlElement(name="Page")
    List<PageType> page;

    @XmlElement(name="Group)
    List<GroupType> group;

    @XmlElement(name="Resources")
    ResourcesType resources;
    ...
}
@xmlacessortype(xmlacesstype.FIELD)
公共类GroupType{
@xmlement(name=“Page”)
列表页;
@xmlement(name=“组)
列表组;
@xmlement(name=“Resources”)
资源体育资源;
...
}
如果您是从XML模式生成类,那么可以使用外部绑定文件来指定为
GroupType

了解更多信息


从POJO开始,您可以对类进行如下注释:

@XmlAccessorType(XmlAccessType.FIELD)
public class GroupType {
    @XmlElement(name="Page")
    List<PageType> page;

    @XmlElement(name="Group)
    List<GroupType> group;

    @XmlElement(name="Resources")
    ResourcesType resources;
    ...
}
@xmlacessortype(xmlacesstype.FIELD)
公共类GroupType{
@xmlement(name=“Page”)
列表页;
@xmlement(name=“组)
列表组;
@xmlement(name=“Resources”)
资源体育资源;
...
}
如果您是从XML模式生成类,那么可以使用外部绑定文件来指定为
GroupType

了解更多信息


我无法让它为我工作。不过,我确实意识到,如果没有maxOccurs,元素将被放入各自的列表中(并不是说它解决了我的问题……),我无法让它为我工作。不过,我确实意识到,如果没有maxOccurs,元素将被放入各自的列表中(这并不能解决我的问题..)