parseResponse method

Response parseResponse(
  1. String xmlStr
)

Response Message Format:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> soapenv:Body </soapenv:Body> </soapenv:Envelope> xmlStr

Implementation

Response parseResponse(String xmlStr) {
  // create xml parser
  Map? response;
  // explicitArray: Always put child nodes in an array if true; otherwise an array is created only if there is more than one.
  // mergeAttrs: Merge attributes and child elements as properties of the parent, instead of keying attributes off a child attribute object.
  final parser = Xml2Json();
  // parse to object
  parser.parse(xmlStr);
  var xmlObj = parser.toParkerWithAttrs();
  var xmlJson = jsonDecode(xmlObj);
  if (xmlJson != null &&
      xmlJson[EpsonXmlHttpClient._xmlResRoot] != null &&
      xmlJson[EpsonXmlHttpClient._xmlResRoot]
              [EpsonXmlHttpClient._xmlResBody] !=
          null) {
    // get response data
    response = xmlJson[EpsonXmlHttpClient._xmlResRoot]
        [EpsonXmlHttpClient._xmlResBody][EpsonXmlHttpClient._xmlResponse];
  }
  return Response(
    ok: (response != null && (response['_success'] == 'true')) ? true : false,
    body: response,
  );
}