
HarryDeveloper
Programming Kotlin - XML Builder output not right (page 265)
The code given in the book for XMLBuilder DLS returns the below output - not the one given in the book:
Eich
Gosling
Matz
The below else part of the toString method -
“”"$indent<$name$attributesValues>
|${children.joinToString("\n") { it.toString(indentation + DEPTH) }}
|$indent</$name>""".trimMargin()
has to be changed a bit, with joinToString taking a prefix of a new line (\n) along with the new line separator, like below -
“”"$indent<$name$attributesValues>
|${children.joinToString("\n")("\n") { it.toString(indentation + DEPTH) }}
|$indent</$name>""".trimMargin()
To get the necessary output:
Eich Gosling MatzPlease correct me if I am wrong.
Thanks.
First Post!

venkats
Hi Eich,
Thank you for the note. I apologize, looks like the xml output was suppressed and I am not able to see the output that you are seeing.
I just ran the code and it seems to produced the desired output without the extra argument.
Regards,
Venkat
Popular Pragmatic topics







Modern Front-End Development for Rails - application does not start after run bin/setup (page xviii)



Other popular topics









Latest in PragProg
Latest (all)
Categories:
Popular Portals
- /elixir
- /rust
- /wasm
- /ruby
- /erlang
- /phoenix
- /keyboards
- /js
- /rails
- /python
- /security
- /go
- /swift
- /vim
- /clojure
- /java
- /haskell
- /emacs
- /svelte
- /onivim
- /typescript
- /crystal
- /c-plus-plus
- /tailwind
- /kotlin
- /gleam
- /react
- /flutter
- /elm
- /ocaml
- /vscode
- /opensuse
- /ash
- /centos
- /php
- /deepseek
- /scala
- /zig
- /html
- /debian
- /nixos
- /lisp
- /agda
- /react-native
- /textmate
- /sublime-text
- /kubuntu
- /arch-linux
- /revery
- /ubuntu
- /manjaro
- /spring
- /django
- /diversity
- /nodejs
- /lua
- /slackware
- /julia
- /c
- /neovim