Class XmlPrintStream

    • Constructor Detail

      • XmlPrintStream

        public XmlPrintStream​(OutputStream outputStream)
        Constructor.
        Parameters:
        outputStream - An OutputStream to which the formatted output will be sent.
    • Method Detail

      • openElement

        public void openElement​(String name)
        Open an XML element with the given name. A call to closeElement() will output the appropriate XML closing tag. This class remembers the tag names.
        Parameters:
        name - Name of the XML element to open.
      • openElement

        public void openElement​(String name,
                                Map<?,​?> attributes)
        Open an XML element with the given name, and attributes. A call to closeElement() will output the appropriate XML closing tag. This class remembers the tag names.
        Parameters:
        name - Name of the XML element to open.
        attributes - A map of name value pairs which will be used to add attributes to the element. Normally you can use Map<String,String> but if you want specify the attribute format use Map<String, XMLAttribute>. In particular, attributes containing json can be processed to avoid escaping of double quote, but wrapping the attribute in a single quote
      • openElement

        public void openElement​(String name,
                                Object... attributes)
        Open an XML element with the given name, and attributes. A call to closeElement() will output the appropriate XML closing tag. This class remembers the tag names. The String parameters are taken to be alternatively names and values. Any odd value at the end of the list is added as a valueless attribute.
        Parameters:
        name - Name of the element.
        attributes - Attributes in name value pairs. Normally you can use pair of String,String but if you want specify the attribute format use pair of String, XMLAttribute. In particular, attributes containing json can be processed to avoid escaping of double quote, but wrapping the attribute in a single quote
      • closeElement

        public void closeElement()
        Close an element previously created with openElement().
      • printElement

        public void printElement​(String elementName,
                                 Object value)
        Output a complete element with the given content.
        Parameters:
        elementName - Name of element.
        value - Content of element.
      • printElement

        public void printElement​(String name,
                                 String value,
                                 Object... attributes)
        Output an element with the given content (value). The opening and closing tags are output in a single operation.
        Parameters:
        name - Name of the element.
        value - Contents of the element.
        attributes - Alternate names and values of attributes for the element. Normally you can use pair of String,String but if you want specify the attribute format use pair of String, XMLAttribute. In particular, attributes containing json can be processed to avoid escaping of double quote, but wrapping the attribute in a single quote
      • printElement

        public void printElement​(String elementName,
                                 Map<?,​?> attributes)
        Output a complete element with the given attributes.
        Parameters:
        elementName - Name of element.
        attributes - A map of name value pairs which will be used to add attributes to the element. Normally you can use Map<String,String> but if you want specify the attribute format use Map<String, XMLAttribute>. In particular, attributes containing json can be processed to avoid escaping of double quote, but wrapping the attribute in a single quote
      • printElement

        public void printElement​(String elementName,
                                 String value,
                                 Map<?,​?> attributes)
        Output a complete element with the given content and attributes.
        Parameters:
        elementName - Name of element.
        value - Content of element.
        attributes - A map of name value pairs which will be used to add attributes to the element. Normally you can use Map<String,String> but if you want specify the attribute format use Map<String, XMLAttribute>. In particular, attributes containing json can be processed to avoid escaping of double quote, but wrapping the attribute in a single quote
      • printElement

        public void printElement​(String name)
        Output a complete empty element.
        Parameters:
        name - Name of element.
      • printComment

        public void printComment​(String comment)
        Output a comment.
        Parameters:
        comment - Comment text.
      • escape

        public String escape​(String in)
        Translate reserved XML characters to XML entities.
        Parameters:
        in - Input string.
      • escape

        public String escape​(String in,
                             XMLAttribute.Format format)
        Translate reserved XML characters to XML entities.
        Parameters:
        in - Input string.
        format - Input format. The Json format does not escape ", but it escapes ' !
      • removeNewLines

        public static String removeNewLines​(String textContent)
        Replace multiple newline characters with a single space.
        Parameters:
        textContent - input String