ReadToDescendant method
Advances to the next descendant element with the given local name and namespace URI, like .NET XmlReader.ReadToDescendant. Returns false (and leaves the reader on the current element's end tag) when there is none.
Implementation
Future<bool> ReadToDescendant(String localName, String namespaceUri) async {
bool matches() =>
_current is XmlStartElementEvent &&
LocalName == localName &&
(NamespaceURI ?? "") == namespaceUri;
if (!_isStarted) {
while (await Read()) {
if (matches()) {
return true;
}
}
return false;
}
final current = _current;
if (current is! XmlStartElementEvent || current.isSelfClosing) {
return false;
}
var depth = 0;
while (await Read()) {
final event = _current;
if (event is XmlStartElementEvent) {
if (matches()) {
return true;
}
if (!event.isSelfClosing) {
depth++;
}
} else if (event is XmlEndElementEvent) {
if (depth == 0) {
return false;
}
depth--;
}
}
return false;
}