getElement method

  1. @override
XmlElement? getElement(
  1. String name, {
  2. String? namespace,
})
inherited

Return the first child element with the given name, or null.

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

For example:

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

Implementation

@override
XmlElement? getElement(String name, {String? namespace}) {
  final tester = createNameMatcher(name, namespace);
  for (final node in children) {
    if (node is XmlElement && tester(node)) {
      return node;
    }
  }
  return null;
}