Class PlanitXmlWriterUtils


  • public class PlanitXmlWriterUtils
    extends Object
    Utilities for creating and using basic Java xml writers
    Author:
    markr
    • Constructor Detail

      • PlanitXmlWriterUtils

        public PlanitXmlWriterUtils()
    • Method Detail

      • createXMLWriter

        public static Pair<XMLStreamWriter,​Writer> createXMLWriter​(Path xmlFilePath)
                                                                  throws PlanItException
        create an xml stream writer for the given path
        Parameters:
        xmlFilePath - to create the writer for
        Returns:
        created xml stream writer and writer instances
        Throws:
        PlanItException - thrown if error
      • writeIndentation

        public static void writeIndentation​(XMLStreamWriter xmlWriter,
                                            int indentationLevel)
                                     throws XMLStreamException
        add indentation to stream at current indentation level via tabs
        Parameters:
        xmlWriter - to use
        indentationLevel - to use
        Throws:
        XMLStreamException - thrown if error
      • writeEmptyElement

        public static void writeEmptyElement​(XMLStreamWriter xmlWriter,
                                             String xmlElementName,
                                             int indentationLevel)
                                      throws XMLStreamException
        Write an empty element (with indentation), e.g. <xmlElementName>
        Parameters:
        xmlWriter - to use
        xmlElementName - element to start tag, e.g. <xmlElementName>
        indentationLevel - to use
        Throws:
        XMLStreamException - thrown if error
      • writeStartElementNewLine

        public static void writeStartElementNewLine​(XMLStreamWriter xmlWriter,
                                                    String xmlElementName,
                                                    int indentationLevel)
                                             throws XMLStreamException
        Write a start element (with indentation) and add newline afterwards
        Parameters:
        xmlWriter - to use
        xmlElementName - element to start tag, e.g. <xmlElementName>
        indentationLevel - to use
        Throws:
        XMLStreamException - thrown if error
      • writeEndElementNewLine

        public static void writeEndElementNewLine​(XMLStreamWriter xmlWriter,
                                                  int indentationLevel)
                                           throws XMLStreamException
        Write an end element and add newline afterwards
        Parameters:
        xmlWriter - to use
        indentationLevel - to use
        Throws:
        XMLStreamException - thrown if error