setAttribute method

  1. @override
void setAttribute(
  1. String name,
  2. String? value,
  3. {String? namespace}
)

Set the attribute value with the given fully qualified name to value. If an attribute with the name already exist, its value is updated. If the value is null, the attribute is removed.

Implementation

@override
void setAttribute(String name, String? value, {String? namespace}) {
  final index = attributes.indexWhere(createNameMatcher(name, namespace));
  if (index < 0) {
    if (value != null) {
      final prefix = namespace == null
          ? null
          : lookupNamespacePrefix(this as dynamic, namespace);
      attributes.add(XmlAttribute(XmlName(name, prefix), value));
    }
  } else {
    if (value != null) {
      attributes[index].value = value;
    } else {
      attributes.removeAt(index);
    }
  }
}