Interface XMLWriter

All Known Implementing Classes:
PrettyPrintXMLWriter

public interface XMLWriter
Interface for tools writing XML files. XMLWriters are not thread safe and must not be accessed concurrently.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addAttribute(String key, String value)
    Add a XML attribute to the current XML Element.
    void
    End the previously opened element.
    void
    setDocType(String docType)
    Sets the DOCTYPE of the document.
    void
    setEncoding(String encoding)
    Sets the encoding of the document.
    void
    Start an XML Element tag.
    void
    Add preformatted markup to the current element tag.
    void
    Add text to the current element tag.
  • Method Details

    • setEncoding

      void setEncoding(String encoding)
      Sets the encoding of the document. If not set, UTF-8 is used.
      Parameters:
      encoding - the encoding
      Throws:
      IllegalStateException - if the generation of the document has already started
    • setDocType

      void setDocType(String docType)
      Sets the DOCTYPE of the document.
      Parameters:
      docType - the docType
      Throws:
      IllegalStateException - if the generation of the document has already started
    • startElement

      void startElement(String name) throws IOException
      Start an XML Element tag.
      Parameters:
      name - the name of the tag
      Throws:
      IOException - if starting the element fails
    • addAttribute

      void addAttribute(String key, String value) throws IOException
      Add a XML attribute to the current XML Element. This method must get called immediately after startElement(String).
      Parameters:
      key - The key of the attribute.
      value - The value of the attribute.
      Throws:
      IllegalStateException - if no element tag is currently in process
      IOException - if adding the attribute fails.
    • writeText

      void writeText(String text) throws IOException
      Add text to the current element tag. This performs XML escaping to guarantee well-formed content.
      Parameters:
      text - The text which should be written.
      Throws:
      IllegalStateException - if no element tag got started yet
      IOException - if writing the text fails.
    • writeMarkup

      void writeMarkup(String text) throws IOException
      Add preformatted markup to the current element tag.
      Parameters:
      text - the text which should be written
      Throws:
      IllegalStateException - if no element tag is started yet
      IOException - if writing the markup fails
    • endElement

      void endElement() throws IOException
      End the previously opened element.
      Throws:
      IOException - if ending the element fails.
      See Also: