XMLNode.fromXmlElement constructor

XMLNode.fromXmlElement(
  1. XmlElement element
)

Because this API is better ;) Don't use in production. Just for testing

Implementation

factory XMLNode.fromXmlElement(XmlElement element) {
  final attributes = <String, String>{};

  for (final attribute in element.attributes) {
    attributes[attribute.name.qualified] = attribute.value;
  }

  if (element.childElements.isEmpty) {
    return XMLNode(
      tag: element.name.qualified,
      attributes: attributes,
      text: element.innerText,
    );
  } else {
    return XMLNode(
      tag: element.name.qualified,
      attributes: attributes,
      children:
          element.childElements.toList().map(XMLNode.fromXmlElement).toList(),
    );
  }
}