Skip to content

Commit ab07818

Browse files
ashawleybiswanaths
authored andcommitted
Nested XML adds empty xmlns attribute #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 5fb415a commit ab07818

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
@@ -164,6 +164,15 @@ class XMLTest {
164164
}
165165
}
166166

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

0 commit comments

Comments
 (0)