Java 多类型列表注释转换:JAXB到SimpleXML
我试图将一些JAXB xjc.exe生成的类转换为简单的XML类。我不知道如何注释动态元素。例如,在模式中,我有: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
<!-- 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)
})
私人名单;
}