namespaceUri property
The namespace URI, or null
. Can only be resolved when the named entity
has complete and up-to-date XmlHasParent.parent
information.
Implementation
String? get namespaceUri {
// Identify the prefix and local name to match.
final index = name.indexOf(XmlToken.namespace);
final prefix = index < 0 ? null : xmlns;
final local = index < 0 ? xmlns : name.substring(0, index);
// Identify the start element to match.
final start =
this is XmlStartElementEvent ? this as XmlStartElementEvent : parent;
// Walk up the tree to find the matching namespace.
for (var event = start; event != null; event = event.parent) {
for (final attribute in event.attributes) {
if (attribute.namespacePrefix == prefix &&
attribute.localName == local) {
return attribute.value;
}
}
}
// Namespace could not be identified.
return null;
}