Search for the prefix associated with specified namespace URI. @param element the element to start searching from @param namespace the namespace prefix @return the prefix bound to the namespace URI; or null if there is no such namespace
(final DomElement element, final String namespace)
| 375 | * @return the prefix bound to the namespace URI; or null if there is no such namespace |
| 376 | */ |
| 377 | public static String lookupPrefix(final DomElement element, final String namespace) { |
| 378 | final Map<String, DomAttr> attributes = element.getAttributesMap(); |
| 379 | for (final Map.Entry<String, DomAttr> entry : attributes.entrySet()) { |
| 380 | final String name = entry.getKey(); |
| 381 | final DomAttr value = entry.getValue(); |
| 382 | if (name.startsWith("xmlns:") && value.getValue().equals(namespace)) { |
| 383 | return name.substring(6); |
| 384 | } |
| 385 | } |
| 386 | for (final DomNode child : element.getChildren()) { |
| 387 | if (child instanceof DomElement domElement) { |
| 388 | final String prefix = lookupPrefix(domElement, namespace); |
| 389 | if (prefix != null) { |
| 390 | return prefix; |
| 391 | } |
| 392 | } |
| 393 | } |
| 394 | return null; |
| 395 | } |
| 396 | } |
nothing calls this directly
no test coverage detected