我对使用 Jaxb 解组非常陌生,但我认为我已经正确配置了所有内容,但在运行时出现此错误:
javax.xml.bind.UnmarshalException: unexpected element (uri:"http://xml.product.place.com/prod/alerts/v_1_0", local:"Record"). Expected elements are (none)
我正在使用 JaxB 基于几个 XSD 生成的 POJO 来解组一个非常复杂的 XML 文件。
这是 XML 的相关部分:
<PlaceAlerts xmlns="http://xml.product.place.com/prod/alerts/v_1_0"">
<Information>
<ReportType>EIFK</ReportType>
<Number>401ZC00155</Number>
<ReportDate>2005-02-05</ReportDate>
</Information>
<Record>
<id>123</id>
<cid><![CDATA[12327*312457495]]></ccid>
...
</PlaceAlerts>
XML 文件继续,但错误出现在记录开始标记上。
这是 Record.java:
package com.etc.etc.etc;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"id",
"cid",
"alerts"
})
@XmlRootElement(name = "Record")
public class Record {
@XmlElement(required = true)
protected Object id;
@XmlElement(required = true)
protected Object cid;
@XmlElement(name = "Alerts", required = true)
protected Alerts alerts;
public Object getId() {
return id;
}
public void setId(Object value) {
this.id = value;
}
public Object getCid() {
return cid;
}
public void setCid(Object value) {
this.cid = value;
}
public Alerts getAlerts() {
return alerts;
}
public void setAlerts(Alerts value) {
this.alerts = value;
}
}
和 bean 声明:
<bean id="unmarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="packagesToScan">
<list>
<value>com.etc.etc.etc.*</value>
</list>
</property>
</bean>
有什么想法吗?如果您需要查看其他内容,请告诉我。