Remove Specific Namespace from XML

Recently, I needed to come up with a solution to remove a namespace from a scala.xml.Node. I couldn't find anything online that would solves this specific problem. I found some help removing all namespaces from the Node, and built my solution off of that (http://stackoverflow.com/questions/12535014/scala-completely-remove-namespace-from-xml)

But I wanted to share my code to remove a specified namespace incase this helps someone out there trying to do the same thing.

Loading GitHub Gist...


This Snippet of XML rewriting code will loop through all of the Nodes within a given Node. On each of the XML Elements it will take the namespace you want removed and: - remove entire elements that are prefixed with the attribute - remove attributes that are prefixed with the namespace - remove the namespace from the scope of the XML Element

This will result in the following transformation:




When used like this:


Where document is the input scala.xml.Node and transformed is the resulting scala.xml.Node

Comments