Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.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 多类型列表注释转换:JAXB到SimpleXML_Java_Xml_Jaxb_Xsd_Simple Framework - Fatal编程技术网

Java 多类型列表注释转换:JAXB到SimpleXML

Java 多类型列表注释转换:JAXB到SimpleXML,java,xml,jaxb,xsd,simple-framework,Java,Xml,Jaxb,Xsd,Simple Framework,我试图将一些JAXB xjc.exe生成的类转换为简单的XML类。我不知道如何注释动态元素。例如,在模式中,我有: <!-- Message Set Request/Response Pairs and contained requests --> <xsd:element name="QBXMLMsgsRq"> <xsd:complexType> <xsd:choice minOccurs="0" maxOccurs="unb

我试图将一些JAXB xjc.exe生成的类转换为简单的XML类。我不知道如何注释动态元素。例如,在模式中,我有:

<!-- Message Set Request/Response Pairs and contained requests  -->
<xsd:element name="QBXMLMsgsRq">
    <xsd:complexType>
        <xsd:choice minOccurs="0" maxOccurs="unbounded">
            <xsd:element name="HostQueryRq" type="HostQueryRqType"/>
            <xsd:element name="CompanyQueryRq" type="CompanyQueryRqType"/>
            <xsd:element name="CompanyActivityQueryRq" type="CompanyActivityQueryRqType"/>
            <!-- many more of these choices -->
        </xsd:choice>
        <xsd:attribute name="oldMessageSetID" type="STRTYPE"/>
        <!-- some other attributes -->
    </xsd:complexType>
</xsd:element>

当通过xjc.exe运行时,它会为@XmlElement生成以下注释

@XmlElements({
    @XmlElement(name = "HostQueryRq", type = HostQueryRqType.class),
    @XmlElement(name = "CompanyQueryRq", type = CompanyQueryRqType.class),
    @XmlElement(name = "CompanyActivityQueryRq", type = CompanyActivityQueryRqType.class),
    //+ et al
})
protected List<Object> hostQueryRqOrCompanyQueryRqOrCompanyActivityQueryRq;
@XmlElements({
@xmlement(name=“HostQueryRq”,type=HostQueryRqType.class),
@XmlElement(name=“CompanyQueryRq”,type=CompanyQueryRqType.class),
@XmlElement(name=“CompanyActivityQueryRq”,type=CompanyActivityQueryRqType.class),
//+等
})
受保护列表主机QueryRqorCompanyQueryRqorCompanyActivityQueryRq;
那么,如何将这个JAXB结构转换为SimpleXML注释的类结构呢?

答案是用于确定列表类型的可用选项。选中“在单个列表中收集各种类型”。例如:

@Root
public class Example {

   @ElementListUnion({
      @ElementList(entry="int", type=Integer.class, inline=true),
      @ElementList(entry="date", type=Date.class, inline=true),
      @ElementList(entry="text", type=String.class, inline=true)
   })
   private List<Object> list;
}
@Root
公开课范例{
@元素列表联合({
@ElementList(entry=“int”,type=Integer.class,inline=true),
@元素列表(entry=“date”,type=date.class,inline=true),
@ElementList(entry=“text”,type=String.class,inline=true)
})
私人名单;
}