提问人:Mark Yu 提问时间:11/29/2022 更新时间:11/29/2022 访问量:37
如何使用 Jaxb 取消嵌套 xml
How to unmarhsal nested xml using Jaxb
问:
我有一个看起来像这样的 xml,我正在尝试解析它,以便我可以从“RevisionList”元素访问“历史记录”列表。
<vehicleHistoryList ml-update="aware" ml-stage="preload">
<ExtractInfo date="2011-11-11T17:50:41.011-02:00" requestedRevision="4.0">
<LoadTimes>
<entry key="Vehicle History List DAO">1111</entry>
<entry key="Test DAO">111</entry>
</LoadTimes>
<ComponentVersions>
<entry key="Vehicle List Engine">1.44.1-190949</entry>
<entry key="Vehicle List DAO">1.44.1-190949</entry>
<entry key="WebService">1.44.1-190949</entry>
</ComponentVersions>
<debug dateTime="2022-11-28T17:50:41.011-05:00" enabled="false" />
</ExtractInfo>
<RevisionList>
<history Acode="111111" RevCode="1227535.0" EffectiveDate="2022-07-25T00:00:00.000" LockedDate="2022-11-14T22:22:12.670-05:00" Latest_Change_Date="2022-11-11T23:11:46.400-05:00" Latest_Status_Change_Date="2022-11-11T18:03:15.553-05:00" />
<history Acode="222222" RevCode="1192984.1" EffectiveDate="2022-06-14T00:00:00.000" LockedDate="2022-07-25T23:02:06.987-04:00" Latest_Change_Date="2022-11-11T23:11:46.417-05:00" Latest_Status_Change_Date="2022-06-15T07:05:42.470-04:00" Embargo_Date="2049-12-31T00:01:00-05:00" />
</RevisionList>
</vehicleHistoryList>
我想解析它,以便我得到一个“历史”元素的列表。
以下是我尝试创建的模型类,但是当我尝试执行时,我收到UnmarshalException:意外的元素错误
vehicleHistoryList = (VehicleHistoryList) jaxbUnmarshaller.unmarshal(xmlSource);
车辆历史列表.java
@XmlRootElement(name="vehicleHistoryList")
@XmlAccessorType(XmlAccessType.FIELD)
public class VehicleHistoryList implements Serializable {
private static final long serialVersionUID = 6906338837295291920L;
@XmlElementWrapper(name="ExtractInfo")
ExtractInfo extractInfo;
@XmlElementWrapper(name = "RevisionList")
@XmlElement(name="history")
private List<History> history;
public List<History> getHistory() {
return history;
}
public void setHistory(List<History> history) {
this.history = history;
}
}
历史.java
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class History implements Serializable {
private static final long serialVersionUID = 542831991244445544L;
@XmlAttribute(
name = "Acode"
)
private String acode;
@XmlAttribute(
name = "RevCode"
)
private double revcode;
@XmlJavaTypeAdapter(CustomDateTimeAdapter.class)
@XmlAttribute(
name = "EffectiveDate"
)
private Date effectiveDate;
@XmlAttribute(
name = "PriceLevel"
)
private Date priceLevel;
@XmlAttribute(
name = "LockedDate"
)
private Date lockedDate;
@XmlAttribute(
name = "Latest_Change_Date"
)
private Date latestChangeDate;
@XmlAttribute(
name = "Latest_Status_Change_Date"
)
private Date latestStatusChangeDate;
public History() {
}
public String getAcode() {
return acode;
}
public void setAcode(String acode) {
this.acode = acode;
}
}
答: 暂无答案
评论
ExtractInfo
String ml-update, ml-stage;