toElementMap static method

Map<String, dynamic> toElementMap({
  1. required XmlElement node,
})

Takes an XmlElement and creates a map from the attributes and any children elements

Implementation

// TODO: Further describe this
static Map<String, dynamic> toElementMap({required XmlElement node}) {
  Map<String, dynamic> map = <String, dynamic>{};

  try {
    ////////////////
    /* Attributes */
    ////////////////
    List<XmlAttribute> attributes = node.attributes;
    for (XmlAttribute attribute in attributes) {
      String value = attribute.value;
      String name = attribute.name.toString();
      map[name] = value;
    }

    //////////////
    /* Elements */
    //////////////
    List<XmlNode> children = node.children;
    for (XmlNode child in children) {
      if (child is XmlElement) {
        XmlElement e = child;
        String? value = e.value;
        String name = e.name.toString();
        map[name] = value;
      }
    }
  } catch (e) {
    Log().exception(e,
        caller:
            'xml.dart => Map<String,dynamic> toElementMap({XmlElement node})');
  }

  return map;
}