getNthElement method

XmlElement? getNthElement(
  1. int index,
  2. String elementName, {
  3. bool ignoreNestedMatches = true,
})

Recursively checks all elements within this node tree and returns the nth element found named elementName.

index must not be null and must be >= 0.

elementName must not be null or empty.

If ignoreNestedMatches is true, matching elements that are nested within matching elements will not be returned, only the highest level matching elements will be returned. If false, all matching elements will be returned.

Returns null if no element can be found.

Implementation

XmlElement? getNthElement(int index, String elementName,
    {bool ignoreNestedMatches = true}) {
  assert(index >= 0);
  assert(elementName.isNotEmpty);
  return getElementsWhere(
    name: elementName,
    ignoreNestedMatches: ignoreNestedMatches,
    start: index,
    stop: index,
  )?.first;
}