findElements function

Iterable<XmlElement>? findElements(
  1. XmlNode? node,
  2. String name, {
  3. bool recursive = false,
  4. String? namespace,
})

Finds XML elements with the specified name in a node.

If recursive is true, it searches for the elements recursively in the XML tree, otherwise, it only looks for direct children of the node.

If namespace is provided, it searches for elements in the specified namespace. Returns an iterable of XmlElement objects representing the found elements, or null if no elements are found or an error occurs during the search.

Implementation

Iterable<XmlElement>? findElements(
  XmlNode? node,
  String name, {
  bool recursive = false,
  String? namespace,
}) {
  try {
    if (recursive) {
      return node?.findAllElements(name, namespace: namespace);
    } else {
      return node?.findElements(name, namespace: namespace);
    }
  } on StateError {
    return null;
  }
}