We have launched a free Basic Kubernetes Course. Click here to enrol now! Kubernetes is a container orchestration platform used by enterprises worldwide and Kubernetes developers are in high demand!
This article describes how to generate XML using Aalto
Aalto StAX Streaming API can be used to generate XML document.
The key classes responsible for generating XML content are
Create TestGenerateXml class as shown below.
Point the outstream to Console output (see line 16 below).
The following methods are used for XML content generation:
- create start element using writeStartElement() method (e.g. see line 20 below)
- create element content using writeCharacters() method (e.g. see line 22 below)
- create end element using writeEndElement() method (e.g. see line 23 below)
Finally flush the stream writer to print the output on console (see line 37 below).
Note that Aalto shall automatically escape the special character ‘&’ (see line 34 below) when generating XML content.
The output of the program demonstrating XML generation is shown below. In particular, note that the special character ‘&’ in address has been escaped automatically by Aalto.