MCPcopy Create free account
hub / github.com/HtmlUnit/htmlunit / lookupPrefix

Method lookupPrefix

src/main/java/org/htmlunit/util/XmlUtils.java:377–395  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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}

Callers

nothing calls this directly

Calls 9

getValueMethod · 0.95
getAttributesMapMethod · 0.80
substringMethod · 0.80
entrySetMethod · 0.45
getKeyMethod · 0.45
getValueMethod · 0.45
startsWithMethod · 0.45
equalsMethod · 0.45
getChildrenMethod · 0.45

Tested by

no test coverage detected