Woodstox : Bind Namespace Prefix and URI During XML Generation Using StAX

Overview

This article demonstrates how Woodstox can be used to bind namespace URI and prefix during XML generation.

Create TestBindingPrefix class as shown below.

Prefix is bound using the following API methods:

  • XMLStreamWriter2.setPrefix() method for setting the prefix and URI(e.g. see line 28 below)
  • XMLStreamWriter2.setDefaultNamespace() to set the default namespace URI (see line 21 below)

For details of other XML generation API method see related article
here

The output of the program demonstrating binding of namespace prefix and URI is shown below.

In particular, note the namespace prefix ‘s’ and URI ‘https://studytrails.com’ in the generated XML.

Download Source Code for this Program

Leave a Comment