Software Development

How to write XML in Kotin using DOM


This post demonstrates how to write XML files using DOM in Java. For reading XML files, please read this previously posted article – How to read XML in Kotlin using DOM Parser.

We are still using Kotlin 1.1.

Target XML Output

Kotlin Codes

The key idea in building out elements or nodes in memory is to build them out like tree and branches (and even leaves).


Single-line XML

These codes produce an XML file to elements properly indented for readability. At times, we want a single-line XML. For example,

Simple comment out these codes from the above codes.


Got comments or suggestions? We disabled the comments on this site to fight off spammers, but you can still contact us via our Facebook page!.

You Might Also Like