解组对象的数组和数组
嗨,我是很新的XML,Web服务和但我从SOAP Web服务,看起来有点像这样recieving XML:解组对象的数组和数组
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<ArrayOfCreditCardSettlement xmlns="http://schemas.datacontract.org/2004/07/Borgun.Library.Common">
<ns0:CreditCardSettlement xmlns="http://Borgun.Services.Gateway/2010/04/Settlement" xmlns:a="http://schemas.datacontract.org/2004/07/Borgun.Library.Common" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:msgns="http://Borgun.Services.Gateway/2010/04/Settlement" xmlns:ns0="http://schemas.datacontract.org/2004/07/Borgun.Library.Common" xmlns:ns1="http://j2ee.netbeans.org/wsdl/BorgunTestBPEL/entrypoint_getSettlements">
<a:amexAmount>**</a:amexAmount>
<a:amount>**</a:amount>
<a:batches>
<a:CreditCardBatch>
<a:batchdate>***</a:batchdate>
<a:batchnumber>***</a:batchnumber>
<a:currencyCode>***</a:currencyCode>
<a:merchantnumber>***</a:merchantnumber>
<a:settlementRunNumber>***</a:settlementRunNumber>
<a:settlementdate>***</a:settlementdate>
<a:slips>*</a:slips>
<a:sum>***</a:sum>
</a:CreditCardBatch>
.
.
more batches
<a:deductionItems>
<a:CreditCardSettlementDeduction>
<a:amount>***</a:amount>
<a:code>**</a:code>
<a:currencyCode>**</a:currencyCode>
<a:merchantnumber>***</a:merchantnumber>
<a:settlementrunnumber>***</a:settlementrunnumber>
<a:text>***</a:text>
</a:CreditCardSettlementDeduction>
.
. more deductionitems
</ns0:CreditCardSettlement>
.
. more Settlements
我用Netbeans的创建结合JAXB这似乎工作
try
{
JAXBContext jc = JAXBContext.newInstance("is.skyrr.jaxbbinding");
Unmarshaller unmarshaller = jc.createUnmarshaller();
Object o = (Object) unmarshaller.unmarshal(new File("....response3.xml"));
} catch (JAXBException ex)
{
Logger.getLogger(TestDB.class.getName()).log(Level.SEVERE, null, ex);
}
结合被生成,具有“ArrayOfCreditCardSettlement”,“CreditCardSettlement”和ObjectFactory的等。
现在,我可以在这里做的唯一事情就是投向JAXBElement
即JAXBElement a =(JAXBElement)unmarshaller.unmarshal(new File(“... response3.xml”));
也许这就是我应该有的,但从那我该怎么用这个?
我想要那个数组/列表使用,但我不知道下一步该怎么做。
AdditionalInfo: 结合从一个xsd
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "ArrayOfCreditCardSettlement", propOrder = {
"creditCardSettlement"})
public class ArrayOfCreditCardSettlement {
@XmlElement(name = "CreditCardSettlement", nillable = true)
protected List<CreditCardSettlement> creditCardSettlement;
public List<CreditCardSettlement> getCreditCardSettlement() {
if (creditCardSettlement == null) {
creditCardSettlement = new ArrayList<CreditCardSettlement>();
}
return this.creditCardSettlement;
}
为CreditCardSettlement类相似生成。
对象工厂拥有XmlElementDecl将的明确命名的命名空间等来回
JAXBElement有一个值,应该是一个ArrayOfCreditCardSettlement
对象。
下面是一个代码示例,可以给一些提示: http://www.java2s.com/Code/Java/XML/UnmarshalltoJAXBElement.htm
- 我敢肯定,你不能有一个集合作为*对象。
-
您是否设置了POJO和ObjectFactory?您应该能够直接解组到您的目标对象。例如
CreditCardSettlementContainer ccsc = (CreditCardSettlementContainer) unmarshaller.unmarshal(yourFile);
上,如果你是刚刚开始,我强烈建议Simple XML这是多更容易理解和使用,更不要说被更灵活另一方面。
感谢你的链接,我试图直接解组为目标对象,但无论出于何种原因没有奏效。 我没有奢侈的选择SimpleXML,但感谢您的回复 – fogedi 2010-06-03 12:43:38
非常感谢,价值的东西只是完全回避我的视线 – fogedi 2010-06-03 12:17:48