package th.co.ais.ssbsrfc.control; import java.util.List; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBElement; import javax.xml.bind.Unmarshaller; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamReader; import javax.xml.transform.stream.StreamSource; @XmlAccessorType(XmlAccessType.FIELD) class Customer { @XmlElement(name="Version",namespace="http://www.huawei.com/bme/cbsinterface/cbscommon") String Version; @XmlElement(name="ResultCode",namespace="http://www.huawei.com/bme/cbsinterface/cbscommon") String ResultCode; @XmlElement(name="MsgLanguageCode",namespace="http://www.huawei.com/bme/cbsinterface/cbscommon") String MsgLanguageCode; @XmlElement(name="ResultDesc",namespace="http://www.huawei.com/bme/cbsinterface/cbscommon") String ResultDesc; @XmlElement(name="AcctKey",namespace="http://www.huawei.com/bme/cbsinterface/arservices") String AcctKey; @XmlElement(name="AdjustmentInfo",namespace="http://www.huawei.com/bme/cbsinterface/arservices") List AdjustmentInfo; } class AdjustmentInfo{ String BalanceType; String BalanceID; String BalanceTypeName; String OldBalanceAmt; String NewBalanceAmt; String CurrencyID; @XmlElement(name="BalanceID",namespace="http://cbs.huawei.com/ar/wsservice/arcommon") public String getBalanceID() { return BalanceID; } public void setBalanceID(String balanceID) { BalanceID = balanceID; } @XmlElement(name="BalanceTypeName",namespace="http://cbs.huawei.com/ar/wsservice/arcommon") public String getBalanceTypeName() { return BalanceTypeName; } public void setBalanceTypeName(String balanceTypeName) { BalanceTypeName = balanceTypeName; } @XmlElement(name="OldBalanceAmt",namespace="http://cbs.huawei.com/ar/wsservice/arcommon") public String getOldBalanceAmt() { return OldBalanceAmt; } public void setOldBalanceAmt(String oldBalanceAmt) { OldBalanceAmt = oldBalanceAmt; } @XmlElement(name="NewBalanceAmt",namespace="http://cbs.huawei.com/ar/wsservice/arcommon") public String getNewBalanceAmt() { return NewBalanceAmt; } public void setNewBalanceAmt(String newBalanceAmt) { NewBalanceAmt = newBalanceAmt; } @XmlElement(name="CurrencyID",namespace="http://cbs.huawei.com/ar/wsservice/arcommon") public String getCurrencyID() { return CurrencyID; } public void setCurrencyID(String currencyID) { CurrencyID = currencyID; } @XmlElement(name="BalanceType",namespace="http://cbs.huawei.com/ar/wsservice/arcommon") public String getBalanceType() { return BalanceType; } public void setBalanceType(String BalanceType) { this.BalanceType = BalanceType; } } public class TestMain { public static void main(String[] args) throws Exception { XMLInputFactory xif = XMLInputFactory.newFactory(); StreamSource xml = new StreamSource("D:\\car.xml"); XMLStreamReader xsr = xif.createXMLStreamReader(xml); xsr.nextTag(); while(!xsr.getLocalName().equals("ResultHeader")) { xsr.nextTag(); System.out.println(xsr.getLocalName()); System.out.println(xsr.hasNext()); } System.out.println(xsr.hasNext()); xsr.next(); /*while(!xsr.getLocalName().equals("AdjustmentResult")) { xsr.nextTag(); }*/ JAXBContext jc = JAXBContext.newInstance(Customer.class); Unmarshaller unmarshaller = jc.createUnmarshaller(); JAXBElement jb = unmarshaller.unmarshal(xsr, Customer.class); xsr.close(); Customer customer = jb.getValue(); System.out.println("Version:"+customer.Version); System.out.println("ResultCode:"+customer.ResultCode); System.out.println("MsgLanguageCode:"+customer.MsgLanguageCode); System.out.println("ResultDesc:"+customer.ResultDesc); /*System.out.println("AcctKey:"+customer.AcctKey); System.out.println("BalanceID:"+customer.AdjustmentInfo.get(0).getBalanceID()); System.out.println("BalanceType:"+customer.AdjustmentInfo.get(0).getBalanceType()); System.out.println("BalanceTypeName:"+customer.AdjustmentInfo.get(0).getBalanceTypeName()); System.out.println("CurrencyID:"+customer.AdjustmentInfo.get(0).CurrencyID); System.out.println("NewBalanceAmt:"+customer.AdjustmentInfo.get(0).NewBalanceAmt); System.out.println("OldBalanceAmt:"+customer.AdjustmentInfo.get(0).OldBalanceAmt);*/ } }