gpt4 book ai didi

java - 使用 JAXB 根​​据属性将 XML 解码为不同的对象

转载 作者:行者123 更新时间:2023-11-30 10:50:49 25 4
gpt4 key购买 nike

<分区>

我正在尝试解码以下 XML:

<calcElement partname="driver">
<driverXs>300.00</driverXs>
<seq>1</seq>
</calcElement>
<calcElement partname="ratingData">
<baseMiles>6000</baseMiles>
<vehicleGroup>15</vehicleGroup>
<documentVersion>4</documentVersion>
</calcElement>

我有以下类,它们代表上述 2 个 calcElement 实例:

public abstract class CalcElement {

private String partName;

@XmlAttribute
public String getPartName() {
return partName;
}

public void setPartName(String partName) {
this.partName = partName;
}
}

public class DriverCalcElement extends CalcElement {
private String driverXs;
private String seq;

public String getDriverXs() {
return driverXs;
}

public void setDriverXs(String driverXs) {
this.driverXs = driverXs;
}

public String getSeq() {
return seq;
}

public void setSeq(String seq) {
this.seq = seq;
}
}

public class RatingDataCalcElement extends CalcElement {
private String baseMiles;
private String vehicleGroup;
private String documentVersion;

public String getBaseMiles() {
return baseMiles;
}

public void setBaseMiles(String baseMiles) {
this.baseMiles = baseMiles;
}

public String getVehicleGroup() {
return vehicleGroup;
}

public void setVehicleGroup(String vehicleGroup) {
this.vehicleGroup = vehicleGroup;
}

public String getDocumentVersion() {
return documentVersion;
}

public void setDocumentVersion(String documentVersion) {
this.documentVersion = documentVersion;
}
}

但是我无法计算出将注释组合添加到类中以成功解码(和编码)此代码。

我需要向类中添加什么才能使其正常工作?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com