getPrefix method

String? getPrefix(
  1. String namespace, {
  2. Map<String, String> customMappings = const {},
})

Returns the prefix for a given namespace URI.

This method performs a reverse lookup in the mappings to find the first prefix that corresponds to the given namespace URI. Custom mappings are checked first, followed by the standard mappings.

The namespace is the URI to look up, and customMappings are additional mappings to check before the standard ones. Returns the prefix for the namespace, or null if not found.

Implementation

String? getPrefix(
  String namespace, {
  Map<String, String> customMappings = const {},
}) {
  // Check if the namespace is already mapped
  return _getKeyByValue(customMappings, namespace) ??
      _getKeyByValue(_mappings, namespace);
}