getAttributeNode method

  1. @override
XmlAttribute? getAttributeNode(
  1. String name, {
  2. String? namespaceUri,
  3. @Deprecated('Use `namespaceUri` instead') String? namespace,
})

Return the attribute node 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.

For example:

  • element.getAttributeNode('xsd:name') returns the first attribute node with the fully qualified attribute name xsd:name.
  • element.getAttributeNode('name', namespaceUri: '*') returns the first attribute node with the local attribute name name no matter the namespace.
  • element.getAttributeNode('*', namespaceUri: 'http://www.w3.org/2001/XMLSchema') returns the first attribute node within the provided namespace URI.

Implementation

@override
XmlAttribute? getAttributeNode(
  String name, {
  String? namespaceUri,
  @Deprecated('Use `namespaceUri` instead') String? namespace,
}) {
  final tester = createNameMatcher(
    name,
    namespaceUri: namespaceUri ?? namespace,
  );
  for (final attribute in attributes) {
    if (tester(attribute)) {
      return attribute;
    }
  }
  return null;
}