0
这里我XmlRoot类:JAXB河段嵌套的XmlElement实例
@XmlRootElement(name = "IGE")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "IGEType", propOrder = { "altin" })
public class IGEType {
@XmlElement(name = "ALTIN", required = true)
protected List<ALTINType> altin;
public List<ALTINType> getALTIN() {
if (altin == null) {
altin = new ArrayList<ALTINType>();
}
return this.altin;
}
}
然后继任者(子)类根:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "ALTINType", propOrder = { "seanSytl" })
public class ALTINType {
@XmlElement(name = "SEANSytl", required = true)
protected SEANSytlType seanSytl;
}
最后,继任类根的继任者:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "SEANSytlType", propOrder = { "birim", "oncekiKapanis", "enDusuk", "enYuksek", "kapanis", "agirlikliOrtalama", "islemHacmi", "islemMiktari", "bicim", "gram", "islemSayisi" })
public class SEANSytlType {
@XmlElement(required = true)
protected String birim;
@XmlElement(name = "onceki_kapanis", required = true)
protected BigDecimal oncekiKapanis;
@XmlElement(name = "en_dusuk", required = true)
protected BigDecimal enDusuk;
@XmlElement(name = "en_yuksek", required = true)
protected BigDecimal enYuksek;
@XmlElement(required = true)
protected BigDecimal kapanis;
@XmlElement(name = "agirlikli_ortalama", required = true)
protected BigDecimal agirlikliOrtalama;
@XmlElement(name = "islem_hacmi", required = true)
protected BigDecimal islemHacmi;
@XmlElement(name = "islem_miktari", required = true)
protected BigDecimal islemMiktari;
@XmlElement(name = "BICIM", required = true)
protected BigDecimal bicim;
@XmlElement(name = "GRAM", required = true)
protected BigDecimal gram;
@XmlElement(name = "islem_sayisi")
protected int islemSayisi;
}
将myHandler类:
@Override
public void handleXMLtoIABData(RequestTcmbXMLData req) throws HmnServiceException {
try {
JAXBContext jaxbContext = JAXBContext.newInstance(IGEType.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
File XMLfile = new File("C:\\Users\\U067944\\Desktop\\IAB_bülten.xml");
IGEType igeRoot = (IGEType) jaxbUnmarshaller.unmarshal(XMLfile);
**List<SEANSytlType> listofAltinYtl = (List<SEANSytlType>) ((List<ALTINType>) igeRoot.getALTIN()).getSEANSytl();**
for (SEANSytlType altinYtl : listofAltinYtl) {
}
} catch (JAXBException e) {
e.printStackTrace();
}
}
在我的处理程序类我试图达成最后的继任类(列表SEANSytlType),但它不工作。 我得到这个错误:
jvmId:300]的transactionId:3005624292568000] .Root原因:java.lang.ClassCastException:java.util.ArrayList中不能转换为com.ykb.hmn.mdt。 marketdata.xmlparser.iab.ALTINType]
我也在处理,但同样试试这个:
IGEType igeRoot = (IGEType) jaxbUnmarshaller.unmarshal(XMLfile);
String inputDate = igeRoot.getIGEBULTENGUNTR().getGun2();
List<ALTINType> listAltinRoot = (List<ALTINType>) igeRoot.getALTIN();
List<SEANSytlType> listofAltinYtl = (List<SEANSytlType>) listAltinRoot.get(0);
我在哪里错了? 在此先感谢!
感谢您的解释和答案 –