我正在尝试将一些 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;
那么如何将这个 JAXB 结构转换为 SimpleXML 带注释的类结构呢?