Class SimpleXml


  • public class SimpleXml
    extends Object
    The SimpleXml class facilitates the creation of an XML document.
    • Constructor Detail

      • SimpleXml

        public SimpleXml​(PrintWriter w)
                  throws IOException
        Creates a SimpleXml instance using the specified print writer for the output of the XML document.
        Parameters:
        w - The writer to send the XML document to
        Throws:
        IOException - If initialization fails
    • Method Detail

      • getWriter

        public PrintWriter getWriter()
        Returns the print writer used for the output of the XML document.
        Returns:
        The print writer
      • setIndent

        public SimpleXml setIndent​(boolean indent)
        Defines whether the output should use indetation. Default is true.
        Parameters:
        indent - true if the output should use indentation, false otherwise
        Returns:
        The XML writer
      • setEncoding

        public SimpleXml setEncoding​(String encoding)
        Sets the character encoding of the output. Default is UTF-8.
        Parameters:
        encoding - The character encoding
        Returns:
        The XML writer
      • omitXmlDeclaration

        public SimpleXml omitXmlDeclaration​(boolean omit)
        Defines whether the XML declaration should be omitted. Default is false.
        Parameters:
        omit - true if the XML declaration should be omitted, false otherwise
        Returns:
        The XML writer
      • setDocumentLocator

        public SimpleXml setDocumentLocator​(Locator locator)
        Sets the document locator of the output.
        Parameters:
        locator - The document locator
        Returns:
        The XML writer
      • open

        public SimpleXml.Element open​(String name)
                               throws IOException
        Opens and returns a new XML element with the specified name.
        Parameters:
        name - The name of the XML element
        Returns:
        The XML element
        Throws:
        IOException - If output fails
      • open

        public SimpleXml.Element open​(String localName,
                                      String name)
                               throws IOException
        Opens and returns a new XML element with the specified name.
        Parameters:
        localName - The local name of the XML element
        name - The name of the XML element
        Returns:
        The XML element
        Throws:
        IOException - If output fails
      • open

        public SimpleXml.Element open​(String uri,
                                      String localName,
                                      String name)
                               throws IOException
        Opens and returns a new XML element with the specified name.
        Parameters:
        uri - The URI of the XML element
        localName - The local name of the XML element
        name - The name of the XML element
        Returns:
        The XML element
        Throws:
        IOException - If output fails
      • open

        public SimpleXml.Element open​(String name,
                                      String content,
                                      boolean cdata)
                               throws IOException
        Opens and returns a new XML element with the specified name and content.
        Parameters:
        name - The name of the XML element
        content - The content of the XML element
        cdata - true if content should be in a CDATA block, false otherwise
        Returns:
        The XML element
        Throws:
        IOException - If output fails
      • closeDocument

        public void closeDocument()
                           throws IOException
        Closes the XML document after closing all open elements.
        Throws:
        IOException - If output fails