getAttributeNode method

XmlEventAttribute? getAttributeNode(
  1. String name, {
  2. String? namespaceUri,
})

Returns the attribute event with the given name, or null.

Both name and namespaceUri can be a specific String; or '*' to match anything. If no namespaceUri is provided, the fully qualified name is compared; otherwise only the local name is considered.

Implementation

XmlEventAttribute? getAttributeNode(String name, {String? namespaceUri}) {
  for (final attribute in attributes) {
    if (name == '*') {
      if (namespaceUri == null || namespaceUri == '*') {
        return attribute;
      } else if (attribute.namespaceUri == namespaceUri) {
        return attribute;
      }
    } else {
      if (namespaceUri == null) {
        if (attribute.qualifiedName == name) return attribute;
      } else if (namespaceUri == '*') {
        if (attribute.localName == name) return attribute;
      } else {
        if (attribute.localName == name &&
            attribute.namespaceUri == namespaceUri) {
          return attribute;
        }
      }
    }
  }
  return null;
}