[英]JAXB inheritance using substitutionGroup not working when unmarshalling
我在不同的命名空间下有10个模式,每个模式都有一个complexType和关联的元素,这些元素可以替代名为“ Report”的元素,例如:
<xsd:element name="MyReport" type="foo:MyReportType" substitutionGroup="bar:Report"/>
<xsd:element name="Report" abstract="true"/>
当我解组其中包含所有10个报告的XML文档时,执行以下操作时只能找到5个:
JAXBContext context = JAXBContext.newInstance("com.foo.bar");
Unmarshaller unmarshaller = context.createUnmarshaller();
//get root node of xml
JAXBElement<ReportPackage> package = unmarshaller.unmarshal(new StreamSource(new File("example.xml")));
ReportPackage rp = package.getValue();
ReportSection reports = rp.getReports();
List<JAXBElement<?>> reportList = reports.getReport();
//iterate through the 10 reports
for (int i = 0; i < reportList.size(); i++) {
JAXBElement rep = reportList.get(i);
...
}
报告的顺序或xml中报告的数量无关紧要。 始终找到10种报告中相同的5种。 我已经使用了JAXB的参考实现2.24u1和2.1.10(JDK 6版本),但都无济于事。 看来替代组被忽略了。 任何帮助将非常感激!
尝试通过以下方式创建JAXB上下文: JAXBContext.newInstance("package1:package2:package3:...")
其中packageX
是您的ObjectFactories所在的软件包。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.