Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/scala/scala/xml/PrettyPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ class PrettyPrinter(width: Int, step: Int) {
* @param sb the stringbuffer to append to
*/
def format(n: Node, sb: StringBuilder) { // entry point
format(n, null, sb)
format(n, TopScope, sb)
}

def format(n: Node, pscope: NamespaceBinding, sb: StringBuilder) { // entry point
Expand Down Expand Up @@ -253,7 +253,7 @@ class PrettyPrinter(width: Int, step: Int) {
* @param nodes the sequence of nodes to be serialized
* @param pscope the namespace to prefix mapping
*/
def formatNodes(nodes: Seq[Node], pscope: NamespaceBinding = null): String =
def formatNodes(nodes: Seq[Node], pscope: NamespaceBinding = TopScope): String =
sbToString(formatNodes(nodes, pscope, _))

/**
Expand Down
21 changes: 21 additions & 0 deletions src/test/scala/scala/xml/XMLTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -836,4 +836,25 @@ expected closing tag of foo
assertEquals("""<x:foo xmlns:x="gaga"/>""", pp.format(x))
}

@UnitTest
def nodeSeqNs: Unit = {
val x = {
<x:foo xmlns:x="abc"/><y:bar xmlns:y="def"/>
}
val pp = new PrettyPrinter(80, 2)
val expected = """<x:foo xmlns:x="abc"/><y:bar xmlns:y="def"/>"""
assertEquals(expected, pp.formatNodes(x))
}

@UnitTest
def nodeStringBuilder: Unit = {
val x = {
<x:foo xmlns:x="abc"/>
}
val pp = new PrettyPrinter(80, 2)
val expected = """<x:foo xmlns:x="abc"/>"""
val sb = new StringBuilder
pp.format(x, sb)
assertEquals(expected, sb.toString)
}
}