convertXmlNodeToMap function Null safety

Map<String, dynamic> convertXmlNodeToMap(
  1. XmlNode xmlNode
)

Convert xmlNode to Map

Implementation

Map<String, dynamic> convertXmlNodeToMap(XmlNode xmlNode) {
  final map = <String, dynamic>{};

  for (final entry in xmlNode.children) {
    if (entry is XmlElement) {
      switch (entry.children.length) {
        case 1:
          map[entry.name.toString()] = entry.text;
          break;
        case 0:
          print(entry.name.toString());
          map[entry.name.toString()] = null;
          break;
        default:
          map[entry.name.toString()] = convertXmlNodeToMap(entry);
      }
    }
  }
  return map;
}