In Scala REPL:
val input = <outerTag xmlns="http://xyz"> <innerTag> </innerTag> </outerTag>
input\\@"innerTag"
=>
<innerTag xmlns="http://xyz"> </innerTag>
How do I stop Scala do this? Why can’t it just give me <innerTag> </innerTag>? How can I stop this happening (or remove the xmlns attributes simply)?
Thanks!
Joe
Clarification:
My overall task is chopping up an XML file and recombining it. So this node will be taken from beneath the root node (which has the xmlns attribute) and then integrated back into a document under a root which again has the xmlns.
In your input document,
<innerTag>has the logical namespace"http://xyz"because its parent<outerTag>element had that namespace. That’s the way XML namespaces work.When you ask for the
<innerTag>element on its own, Scala copies the namespace declaration from the parent<outerTag>, because the namespace is a logical part of the<innerTag>, even if it wasn’t explicitly stated in the initial document.If you want to remove the namespace, you’ll have to perform some additional processing to do so.