问题
I am trying to access soap webservices in android.
AndroidHttpTransport httpTransport = new AndroidHttpTransport(URL);
...
...
String result = (String) httpTransport.responseDump;
I got the response result string as xml format given below,
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<sampleResponse xmlns="http://impl.test.com">
<sampleReturn>
<clientNameList>
<clientNameList>
<clientID>1</clientID>
</clientNameList>
<clientNameList>
<clientID>2</clientID>
</clientNameList>
</clientNameList>
<message>SUCCESS</message>
</sampleReturn>
</sampleResponse>
</soapenv:Body>
</soapenv:Envelope>
Parsing this xml into Pojo using Simple XML Serialization(simple-xml-2.6.6.jar). Ref: here
Persister persister = new Persister();
UserResponse userResponse = persister.read(UserResponse.class, result);
Now I got the exception as
Element 'Body' does not have a match in class com.test.UserResponse at line 1
For more code information here
How can I fix this?
UserResponse.java(POJO class)
public class UserResponse {
private String message = null;
private Client[] clientNameList = null;
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public void setClientNameList(Client[] clientNameList) {
this.clientNameList = clientNameList;
}
public Client[] getClientNameList() {
return clientNameList;
}
}
and Client.java
public class Client {
private int clientID;
public void setClientID(int clientID) {
this.clientID = clientID;
}
public int getClientID() {
return clientID;
}
}
回答1:
There is a problem in your response. You are getting <clientNameList> two times one after another so that might be causing you a problem in parsing the XML. So, better change your response accordingly.
来源:https://stackoverflow.com/questions/12095437/android-webservice-response-parse-xml-to-pojo-exception