XML Generation Using Aalto

Overview

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
XMLOutputFactory2
and
XMLStreamWriter2
.

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.

Download Source Code for this Program

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.