xmlToMap static method

Map<String, dynamic> xmlToMap(
  1. String soapResponse
)

Implementation

static Map<String, dynamic> xmlToMap(String soapResponse) {
  final transformer = Xml2Json();

  final xmlEnvelope = XmlDocument.parse(soapResponse).getElement('Envelope',
      namespace: 'http://www.w3.org/2003/05/soap-envelope');

  if (xmlEnvelope == null) throw Exception();

  transformer.parse(xmlEnvelope.toXmlString());

  final rootMap =
      json.decode(transformer.toBadgerfish(useLocalNameForNodes: true))
          as Map<String, dynamic>;

  if (!rootMap.containsKey('Envelope')) throw Exception();

  return rootMap['Envelope'];
}