XMLWriter (Apache Tomcat 11.0.22 API Documentation)
Description: declaration: package: org.apache.catalina.util, class: XMLWriter

# Class XMLWriter

java.lang.Object
org.apache.catalina.util.XMLWriter

public class XMLWriter extends Object
XMLWriter helper class.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected StringBuilder`
  `buffer`
  Buffer.
  `static final int`
  `CLOSING`
  Closing tag.
  `protected boolean`
  `lastWriteWasOpen`
  `static final int`
  `NO_CONTENT`
  Element with no content.
  `static final int`
  `OPENING`
  Opening tag.
  `protected final Writer`
  `writer`
  Writer.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `XMLWriter()`
  New XML writer utility that will store its data in an internal buffer.
  `XMLWriter(Writer writer)`
  New XML writer utility that will store its data in an internal buffer and can write it to the specified writer.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `sendData()`
  Send data and reinitializes buffer, if a writer has been specified.
  `String`
  `toString()`
  Retrieve generated XML.
  `void`
  `writeData(String data)`
  Write data.
  `void`
  `writeElement(String namespace, String name, int type)`
  Write an element.
  `void`
  `writeElement(String namespace, String namespaceInfo, String name, int type)`
  Write an element.
  `void`
  `writeProperty(String namespace, String name, String value)`
  Write property to the XML.
  `void`
  `writeRaw(String raw)`
  Write raw XML data.
  `void`
  `writeText(String text)`
  Write text.
  `void`
  `writeXMLHeader()`
  Write XML Header.

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Field Details

  - ### OPENING

    public static final int OPENING
    Opening tag.
    See Also:
      - Constant Field Values

  - ### CLOSING

    public static final int CLOSING
    Closing tag.
    See Also:
      - Constant Field Values

  - ### NO_CONTENT

    public static final int NO_CONTENT
    Element with no content.
    See Also:
      - Constant Field Values

  - ### buffer

    protected StringBuilder buffer
    Buffer.

  - ### writer

    protected final Writer writer
    Writer.

  - ### lastWriteWasOpen

    protected boolean lastWriteWasOpen

- ## Constructor Details

  - ### XMLWriter

    public XMLWriter()
    New XML writer utility that will store its data in an internal buffer.

  - ### XMLWriter

    public XMLWriter(Writer writer)
    New XML writer utility that will store its data in an internal buffer and can write it to the specified writer.

    See `sendData()`

    Parameters:
      `writer` - The writer to use

- ## Method Details

  - ### toString

    public String toString()
    Retrieve generated XML.
    Overrides:
      `toString` in class `Object`
    Returns:
      String containing the generated XML

  - ### writeProperty

    public void writeProperty(String namespace, String name, String value)
    Write property to the XML.
    Parameters:
      `namespace` - Namespace
      `name` - Property name
      `value` - Property value

  - ### writeElement

    public void writeElement(String namespace, String name, int type)
    Write an element.
    Parameters:
      `namespace` - Namespace abbreviation
      `name` - Element name
      `type` - Element type

  - ### writeElement

    public void writeElement(String namespace, String namespaceInfo, String name, int type)
    Write an element.
    Parameters:
      `namespace` - Namespace abbreviation
      `namespaceInfo` - Namespace info
      `name` - Element name
      `type` - Element type

  - ### writeText

    public void writeText(String text)
    Write text.
    Parameters:
      `text` - Text to append

  - ### writeRaw

    public void writeRaw(String raw)
    Write raw XML data.
    Parameters:
      `raw` - Raw XML to append

  - ### writeData

    public void writeData(String data)
    Write data.
    Parameters:
      `data` - Data to append

  - ### writeXMLHeader

    public void writeXMLHeader()
    Write XML Header.

  - ### sendData

    public void sendData() throws IOException
    Send data and reinitializes buffer, if a writer has been specified.
    Throws:
      `IOException` - Error writing XML data