in src/main/java/org/apache/maven/xinclude/stax/XIncludeStreamReader.java [469:500]
private Map<String, String> getAllNamespaces(Node element) {
Map<String, String> namespaces = new LinkedHashMap<>();
// Walk up the tree to collect all inherited namespaces
Node current = element;
while (current instanceof Element elem) {
NamedNodeMap attributes = elem.getAttributes();
// Check all attributes for namespace declarations
for (int i = 0; i < attributes.getLength(); i++) {
Attr attr = (Attr) attributes.item(i);
String name = attr.getNodeName();
// Handle xmlns:prefix declarations
if (name.startsWith("xmlns:")) {
String prefix = name.substring(6); // length of "xmlns:"
if (!namespaces.containsKey(prefix)) {
namespaces.put(prefix, attr.getValue());
}
}
// Handle default namespace declaration
else if ("xmlns".equals(name)) {
if (!namespaces.containsKey("")) {
namespaces.put("", attr.getValue());
}
}
}
current = current.getParentNode();
}
// Add empty namespace
if (!namespaces.containsKey("")) {
namespaces.put("", "");
}
return namespaces;
}