Skip to content

Commit 596f183

Browse files
committed
Nested XML adds empty xmlns attribute scala#45
* src/test/scala/scala/xml/XMLTest.scala (namespacesWithNestedXmls): Modified test case by Muntis Grūbe. * src/main/scala/scala/xml/NamespaceBinding.scala (doBuildString): Add TopScope as a value to avoid building the namespace attribute string.
1 parent 9980137 commit 596f183

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/main/scala/scala/xml/NamespaceBinding.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ case class NamespaceBinding(prefix: String, uri: String, parent: NamespaceBindin
7373
}
7474

7575
private def doBuildString(sb: StringBuilder, stop: NamespaceBinding) {
76-
if ((this == null) || (this eq stop)) return // contains?
76+
if (List(null, stop, TopScope).contains(this)) return
7777

7878
val s = " xmlns%s=\"%s\"".format(
7979
(if (prefix != null) ":" + prefix else ""),

src/test/scala/scala/xml/XMLTest.scala

+9
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,15 @@ class XMLTest {
162162
}
163163
}
164164

165+
@UnitTest
166+
def namespacesWithNestedXmls: Unit = {
167+
val foo = <f:foo xmlns:f="fooUrl"></f:foo>
168+
val bar = <b:bar xmlns:b="barUrl">{foo}</b:bar>
169+
val expected = """<b:bar xmlns:b="barUrl"><f:foo xmlns:f="fooUrl"></f:foo></b:bar>"""
170+
val actual = bar.toString
171+
assertEquals(expected, actual)
172+
}
173+
165174
@UnitTest
166175
def validationOfElements: Unit = {
167176
val vtor = new scala.xml.dtd.ElementValidator();

0 commit comments

Comments
 (0)