我曾尝试使用本网站上提出的其他问题,但这些问题都与我正在做的事情无关。
我正在尝试使用 simpleXML 为Android应用程序'反序列化'soap xml。我越来越接近这个,但我在这里碰了一堵砖。
当我运行我的代码时,我收到以下错误:
org.simpleframework.xml.core.PersistenceException: Element 'serviceOrderCT' is already used with @org.simpleframework.xml.Element(name=, type=void, data=false, required=true) on field 'serviceOrderCT' private serviceOrderCT GetServiceOrdersResult.serviceOrderCT at line 26
所以,问题似乎是'GetServiceOrdersResult.java'类(下面的代码),但我无法理解它是什么。
我已经在这里工作了好几个小时而且无处可去。
帮助通过这个问题将不胜感激。
感谢。
[编辑:这是XML文件]
<GetServiceOrdersResponse xmlns="http://tempuri.org/">
<GetServiceOrdersResult xmlns:a="http://schemas.datacontract.org/2004/07/MobileWebService" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:serviceOrderCT>
<a:_bill_to_Customer_No_>xxxxx</a:_bill_to_Customer_No_>
<a:_bill_to_Name>xxxxxxx</a:_bill_to_Name>
<a:_customer_No_ i:nil="true" />
<a:_description />
<a:_fix_By_Date>xxxxxxxxxxxxx</a:_fix_By_Date>
<a:_fix_By_Time />
<a:_fixed_Date>xxxxxxxxxxxx</a:_fixed_Date>
<a:_fixed_Time>xxxxxxxxxxxxxx</a:_fixed_Time>
<a:_name>xxxxxxxxxxxxxxx</a:_name>
<a:_no_>xxxxxxxxxxxxxxxxxxx</a:_no_>
<a:_order_Date>xxxxxxxxxxxxxxx</a:_order_Date>
<a:_order_Time>xxxxxxxxxxxxx</a:_order_Time>
<a:_responded_Date>xxxxxxxxxxxxxxxxxx</a:_responded_Date>
<a:_responded_Time />
<a:_response_Date>xxxxxxxxxxxxxxxxxx</a:_response_Date>
<a:_response_Time>xxxxxxxxxxxxxxxxxxxx</a:_response_Time>
<a:_transaction_Status>xxxxxxxxxxxxxxx</a:_transaction_Status>
<a:_your_Reference />
</a:serviceOrderCT>
<a:serviceOrderCT>
a:_bill_to_Customer_No_>xxxxx</a:_bill_to_Customer_No_>
<a:_bill_to_Name>xxxxxxx</a:_bill_to_Name>
<a:_customer_No_ i:nil="true" />
<a:_description />
<a:_fix_By_Date>xxxxxxxxxxxxx</a:_fix_By_Date>
<a:_fix_By_Time />
<a:_fixed_Date>xxxxxxxxxxxx</a:_fixed_Date>
<a:_fixed_Time>xxxxxxxxxxxxxx</a:_fixed_Time>
<a:_name>xxxxxxxxxxxxxxx</a:_name>
<a:_no_>xxxxxxxxxxxxxxxxxxx</a:_no_>
<a:_order_Date>xxxxxxxxxxxxxxx</a:_order_Date>
<a:_order_Time>xxxxxxxxxxxxx</a:_order_Time>
<a:_responded_Date>xxxxxxxxxxxxxxxxxx</a:_responded_Date>
<a:_responded_Time />
<a:_response_Date>xxxxxxxxxxxxxxxxxx</a:_response_Date>
<a:_response_Time>xxxxxxxxxxxxxxxxxxxx</a:_response_Time>
<a:_transaction_Status>xxxxxxxxxxxxxxx</a:_transaction_Status>
<a:_your_Reference />
</a:serviceOrderCT>
</GetServiceOrdersResult>
</GetServiceOrdersResponse>
Envelope.java
import org.simpleframework.xml.Element;
import org.simpleframework.xml.Root;
@Root
public class Envelope {
@Element(name = "Body")
private Body body;
public Body getBody() {
return body;
}
}
Body.java
import org.simpleframework.xml.Element;
import org.simpleframework.xml.ElementList;
import org.simpleframework.xml.Path;
import org.simpleframework.xml.Root;
import java.util.List;
public class Body {
@Element(name = "GetServiceOrdersResponse")
private GetServiceOrdersResponse getServiceOrdersResponse;
public GetServiceOrdersResponse getServiceOrdersResponse() {
return getServiceOrdersResponse;
}
}
GetServiceOrdersResponse.java
import org.simpleframework.xml.Element;
import org.simpleframework.xml.Path;
public class GetServiceOrdersResponse {
@Element(name = "GetServiceOrdersResult")
private GetServiceOrdersResult getServiceOrdersResult;
public GetServiceOrdersResult getGetServiceOrdersResult() {
return getServiceOrdersResult;
}
}
GetServiceOrdersResult.java
import org.simpleframework.xml.Element;
import org.simpleframework.xml.ElementList;
import org.simpleframework.xml.Path;
import org.simpleframework.xml.Root;
import java.util.List;
public class GetServiceOrdersResult {
@Element
private serviceOrderCT serviceOrderCT;
public serviceOrderCT getServiceOrderCT() {
return serviceOrderCT;
}
}
serviceOrderCT
import org.simpleframework.xml.Element;
import org.simpleframework.xml.Namespace;
import org.simpleframework.xml.Root;
public class serviceOrderCT {
@Element(name = "_bill_to_Customer_No_", required = false)
private String billToCustomerNo;
@Element(name = "_bill_to_Name", required = false)
private String billToName;
@Element(name = "_customer_No_", required = false)
private String customerNo;
@Element(name = "_description", required = false)
private String description;
@Element(name = "_fix_By_Date", required = false)
private String fixByDate;
@Element(name = "_fix_By_Time", required = false)
private String fixByTime;
@Element(name = "_fixed_Date", required = false)
private String fixedDate;
@Element(name = "_fixed_Time", required = false)
private String fixedTime;
@Element(name = "_name", required = false)
private String name;
@Element(name = "_no_", required = false)
private String no;
@Element(name = "_order_Date", required = false)
private String orderDate;
@Element(name = "_order_Time", required = false)
private String orderTime;
@Element(name = "_responded_Date", required = false)
private String respondedDate;
@Element(name = "_responded_Time", required = false)
private String respondedTime;
@Element(name = "_response_Date", required = false)
private String responseDate;
@Element(name = "_response_Time", required = false)
private String responseTime;
@Element(name = "_transaction_Status", required = false)
private String transactionStatus;
@Element(name = "_your_Reference", required = false)
private String yourReference;
public serviceOrderCT() {
}
public String getBillToCustomerNo() {
return billToCustomerNo;
}
public void setBillToCustomerNo(String billToCustomerNo) {
this.billToCustomerNo = billToCustomerNo;
}
public String getBillToName() {
return billToName;
}
public void setBillToName(String billToName) {
this.billToName = billToName;
}
public String getCustomerNo() {
return customerNo;
}
public void setCustomerNo(String customerNo) {
this.customerNo = customerNo;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getFixByDate() {
return fixByDate;
}
public void setFixByDate(String fixByDate) {
this.fixByDate = fixByDate;
}
public String getFixByTime() {
return fixByTime;
}
public void setFixByTime(String fixByTime) {
this.fixByTime = fixByTime;
}
public String getFixedDate() {
return fixedDate;
}
public void setFixedDate(String fixedDate) {
this.fixedDate = fixedDate;
}
public String getFixedTime() {
return fixedTime;
}
public void setFixedTime(String fixedTime) {
this.fixedTime = fixedTime;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getNo() {
return no;
}
public void setNo(String no) {
this.no = no;
}
public String getOrderDate() {
return orderDate;
}
public void setOrderDate(String orderDate) {
this.orderDate = orderDate;
}
public String getOrderTime() {
return orderTime;
}
public void setOrderTime(String orderTime) {
this.orderTime = orderTime;
}
public String getRespondedDate() {
return respondedDate;
}
public void setRespondedDate(String respondedDate) {
this.respondedDate = respondedDate;
}
public String getRespondedTime() {
return respondedTime;
}
public void setRespondedTime(String respondedTime) {
this.respondedTime = respondedTime;
}
public String getResponseDate() {
return responseDate;
}
public void setResponseDate(String responseDate) {
this.responseDate = responseDate;
}
public String getResponseTime() {
return responseTime;
}
public void setResponseTime(String responseTime) {
this.responseTime = responseTime;
}
public String getTransactionStatus() {
return transactionStatus;
}
public void setTransactionStatus(String transactionStatus) {
this.transactionStatus = transactionStatus;
}
public String getYourReference() {
return yourReference;
}
public void setYourReference(String yourReference) {
this.yourReference = yourReference;
}
}
Main.java
import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.core.Persister;
import java.io.File;
public class Main {
public static void main(String[] args) {
try {
Serializer serializer = new Persister();
File result = new File("C:\\Users\\xxxxxxxx\\Documents\\file.xml");
Envelope example = serializer.read(Envelope.class, result);
System.out.println(example.getBody().getServiceOrdersResponse().getGetServiceOrdersResult().getServiceOrderCT().getBillToCustomerNo());
} catch (Exception e) {
e.printStackTrace();
}
}
}
答案 0 :(得分:-2)
所以,我在寻求帮助后的第二天,在我自己的再次上解决了我的问题。
如果要获取所有三个serviceOrderCT,则必须实现ElementList。它只是拿起一个。
如果我删除了其他两个,我会得到回报。
建议读者阅读本文,坚持使用官方文档。它会帮助你很多。 http://simple.sourceforge.net/download/stream/doc/tutorial/tutorial.php#list