Next, you must recursively remove namespaces from both elements and attributes.
def removeNamespaces(node: Node): Node = { node match { case elem: Elem => { elem.copy( scope = TopScope, prefix = null, attributes = removeNamespacesFromAttributes(elem.attributes), child = elem.child.map(removeNamespaces) ) } case other => other } } def removeNamespacesFromAttributes(metadata: MetaData): MetaData = { metadata match { case UnprefixedAttribute(k, v, n) => new UnprefixedAttribute(k, v, removeNamespacesFromAttributes(n)) case PrefixedAttribute(pre, k, v, n) => new UnprefixedAttribute(k, v, removeNamespacesFromAttributes(n)) case Null => Null } }
It worked, at least in the following test case:
<foo xmlns:xoox="http://example.com/xoox"> <baz xoox:asd="first">123</baz> <xoox:baz xoox:asd="second">456</xoox:baz> </foo>
source share