namespaces property
Return the in-scope namespaces of this node.
Implementation
@override
Iterable<XmlNamespace> get namespaces sync* {
final prefixes = <String>{};
for (XmlNode? current = this; current != null; current = current.parent) {
if (current is XmlElement) {
for (final attribute in current.attributes) {
if (attribute.name.prefix == ns.xmlns) {
if (prefixes.add(attribute.name.local) &&
attribute.value.isNotEmpty) {
yield XmlNamespace(attribute.name.local, attribute.value)
..attachParent(current);
}
} else if (attribute.name.local == ns.xmlns &&
attribute.name.prefix == null) {
if (prefixes.add('') && attribute.value.isNotEmpty) {
yield XmlNamespace('', attribute.value)..attachParent(current);
}
}
}
}
}
if (prefixes.add(ns.xml)) {
yield XmlNamespace(ns.xml, ns.xmlUri)..attachParent(root);
}
}