Я использую Retrofit2 + SimpleXML + RxJava для отправки XML-запросов и анализа XML-ответов в POJO. Все работает отлично, за исключением разбора / сериализации ответов xml с вложенными блоками CDATA с xmls внутри. Просто мне нужно преобразовать строку XML в POJO через SimpleXML.
Я пробовал разные способы.
Мой вопрос очень похож на Не могу разобрать xml с блоком CDATA, используя SimpleXML и Retrofit
Я делаю такой запрос:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ret="someService">
<soapenv:Body>
<ret:WebRequest>
<ret:pxmlRequest><request><![CDATA[<Request>
<Request_ID>login</Request_ID>
<Request_Body>
<LoginID>380123456789</LoginID>
<Password>password</Password>
</Request_Body>
</Request>
]]></request></ret:pxmlRequest>
<ret:pxmlResponse></ret:pxmlResponse>
</ret:WebRequest>
</soapenv:Body>
</soapenv:Envelope>
Я получил такой ответ:
<Soap:Envelope xmlns:Soap="http://schemas.xmlsoap.org/soap/envelope/">
<Soap:Body>
<WebRequest_Result xmlns="someService">
<pxmlRequest><![CDATA[
<Request>
<Request_ID>login</Request_ID>
<Request_Body>
<LoginID>380123456789</LoginID>
<Password>password</Password>
</Request_Body>
</Request>
]]></pxmlRequest>
<pxmlResponse><![CDATA[
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Request_ID>login</Request_ID>
<Response_Code>0000</Response_Code>
<Response_Text />
<Response_Body>
<LoginID>380123456789</LoginID>
<Password>some_password</Password>
<AccountID />
<ContactID />
<Email />
<FirstName />
<LastName />
<MiddleName />
<Gender />
<Phone />
<Address1 />
<Address2 />
<PostCode />
<SateProvinceRegion />
<Country />
<ExternalID />
<ExternalSystem />
<City />
<CardID />
<VehicleInfoFilled>0</VehicleInfoFilled>
<Login_Card_Buffer>
<ClubCode>some club</ClubCode>
<ClubDescription>some club</ClubDescription>
<CardNo>100000000</CardNo>
<CardholderName>Name</CardholderName>
<Blocked>false</Blocked>
</Login_Card_Buffer>
<Login_Card_Buffer>
<ClubCode>some club</ClubCode>
<ClubDescription>some club</ClubDescription>
<CardNo>some_card_no</CardNo>
<CardholderName>some_name</CardholderName>
<Blocked>false</Blocked>
</Login_Card_Buffer>
</Response_Body>
</Response>
]]></pxmlResponse>
</WebRequest_Result>
</Soap:Body>
</Soap:Envelope>
Мне нужно проанализировать все данные из ответа в PostAuthResponseEnvelope.java, а затем проанализировать вложенный раздел CDATA внутри узла в Response.java.
Вот эти классы:
import org.simpleframework.xml.Element;
import org.simpleframework.xml.Path;
import org.simpleframework.xml.Root;
@Root(name="Envelope")
public class PostAuthResponseEnvelope_1 {
@Element(name="pxmlRequest", required=false)
@Path("Body/WebRequest_Result")
String pxmlRequest;
@Element(name="pxmlResponse", required=false)
@Path("Body/WebRequest_Result")
Response pxmlResponse;
public String getPxmlRequest() {return this.pxmlRequest;}
public void setPxmlRequest(String value) {this.pxmlRequest = value;}
public Response getPxmlResponse() {return this.pxmlResponse;}
public void setPxmlResponse(Response value) {this.pxmlResponse = value;}
}
import org.simpleframework.xml.Element;
import org.simpleframework.xml.ElementList;
import org.simpleframework.xml.Root;
import java.util.List;
@Root(name="Response")
public class Response {
@Element(name="Response_Code", required=false, data = true)
String responseCode;
@Element(name="Request_ID", required=false, data = true)
String requestID;
@Element(name="Response_Text", required=false, data = true)
String responseText;
@Element(name="Response_Body", required=false, data = true)
ResponseBody responseBody;
public String getResponseCode() {return this.responseCode;}
public void setResponseCode(String value) {this.responseCode = value;}
public String getRequestID() {return this.requestID;}
public void setRequestID(String value) {this.requestID = value;}
public String getResponseText() {return this.responseText;}
public void setResponseText(String value) {this.responseText = value;}
public ResponseBody getResponseBody() {return this.responseBody;}
public void setResponseBody(ResponseBody value) {this.responseBody = value;}
public static class LoginCardBuffer {
@Element(name="CardholderName", required=false)
String cardholderName;
@Element(name="CardNo", required=false)
String cardNo;
@Element(name="ClubDescription", required=false)
String clubDescription;
@Element(name="ClubCode", required=false)
String clubCode;
@Element(name="Blocked", required=false)
String blocked;
public String getCardholderName() {return this.cardholderName;}
public void setCardholderName(String value) {this.cardholderName = value;}
public String getCardNo() {return this.cardNo;}
public void setCardNo(String value) {this.cardNo = value;}
public String getClubDescription() {return this.clubDescription;}
public void setClubDescription(String value) {this.clubDescription = value;}
public String getClubCode() {return this.clubCode;}
public void setClubCode(String value) {this.clubCode = value;}
public String getBlocked() {return this.blocked;}
public void setBlocked(String value) {this.blocked = value;}
}
public static class ResponseBody {
@Element(name="AccountID", required=false)
String accountID;
@Element(name="Email", required=false)
String email;
@Element(name="LoginID", required=false)
String loginID;
@Element(name="FirstName", required=false)
String firstName;
@Element(name="ExternalSystem", required=false)
String externalSystem;
@Element(name="ExternalID", required=false)
String externalID;
@Element(name="Address2", required=false)
String address2;
@Element(name="SateProvinceRegion", required=false)
String sateProvinceRegion;
@ElementList(name="Login_Card_Buffer", required=false, entry="Login_Card_Buffer", inline=true)
List<LoginCardBuffer> loginCardBuffer;
@Element(name="ContactID", required=false)
String contactID;
@Element(name="Gender", required=false)
String gender;
@Element(name="Address1", required=false)
String address1;
@Element(name="City", required=false)
String city;
@Element(name="CardID", required=false)
String cardID;
@Element(name="MiddleName", required=false)
String middleName;
@Element(name="Phone", required=false)
String phone;
@Element(name="Country", required=false)
String country;
@Element(name="LastName", required=false)
String lastName;
@Element(name="PostCode", required=false)
String postCode;
@Element(name="Password", required=false)
String password;
public String getAccountID() {return this.accountID;}
public void setAccountID(String value) {this.accountID = value;}
public String getEmail() {return this.email;}
public void setEmail(String value) {this.email = value;}
public String getLoginID() {return this.loginID;}
public void setLoginID(String value) {this.loginID = value;}
public String getFirstName() {return this.firstName;}
public void setFirstName(String value) {this.firstName = value;}
public String getExternalSystem() {return this.externalSystem;}
public void setExternalSystem(String value) {this.externalSystem = value;}
public String getExternalID() {return this.externalID;}
public void setExternalID(String value) {this.externalID = value;}
public String getAddress2() {return this.address2;}
public void setAddress2(String value) {this.address2 = value;}
public String getSateProvinceRegion() {return this.sateProvinceRegion;}
public void setSateProvinceRegion(String value) {this.sateProvinceRegion = value;}
public List<LoginCardBuffer> getLoginCardBuffer() {return this.loginCardBuffer;}
public void setLoginCardBuffer(List<LoginCardBuffer> value) {this.loginCardBuffer = value;}
public String getContactID() {return this.contactID;}
public void setContactID(String value) {this.contactID = value;}
public String getGender() {return this.gender;}
public void setGender(String value) {this.gender = value;}
public String getAddress1() {return this.address1;}
public void setAddress1(String value) {this.address1 = value;}
public String getCity() {return this.city;}
public void setCity(String value) {this.city = value;}
public String getCardID() {return this.cardID;}
public void setCardID(String value) {this.cardID = value;}
public String getMiddleName() {return this.middleName;}
public void setMiddleName(String value) {this.middleName = value;}
public String getPhone() {return this.phone;}
public void setPhone(String value) {this.phone = value;}
public String getCountry() {return this.country;}
public void setCountry(String value) {this.country = value;}
public String getLastName() {return this.lastName;}
public void setLastName(String value) {this.lastName = value;}
public String getPostCode() {return this.postCode;}
public void setPostCode(String value) {this.postCode = value;}
public String getPassword() {return this.password;}
public void setPassword(String value) {this.password = value;}
}
}
В PostAuthResponseEnvelope.java все разбирается хорошо. Но я не могу разобрать вложенный узел блочной формы CDATA в Response.java.
Пожалуйста, помогите мне разобраться, как правильно разобрать его.