@Test public void testStartDocumentWithoutPrefix() throws Exception { try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { XMLStreamWriter writer = XMLWriterUtil.startDocument(outputStream, null, "test", "namespace"); assertNotNull(writer); assertThat(outputStream.toString(), is("<test xmlns=\"namespace\"")); } }
public static XMLStreamWriter startDocument(ByteArrayOutputStream outputStream, String prefix, String documentRootName, String nameSpaceURI) throws XMLStreamException { XMLStreamWriter writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(outputStream, UTF_8.name()); if (isNullOrEmpty(prefix)) { writer.writeStartElement(documentRootName); writer.setDefaultNamespace(nameSpaceURI); writer.writeDefaultNamespace(nameSpaceURI); } else { writer.writeStartElement(prefix, documentRootName, nameSpaceURI); writer.writeNamespace(prefix, nameSpaceURI); } return writer; }
XMLWriterUtil { public static XMLStreamWriter startDocument(ByteArrayOutputStream outputStream, String prefix, String documentRootName, String nameSpaceURI) throws XMLStreamException { XMLStreamWriter writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(outputStream, UTF_8.name()); if (isNullOrEmpty(prefix)) { writer.writeStartElement(documentRootName); writer.setDefaultNamespace(nameSpaceURI); writer.writeDefaultNamespace(nameSpaceURI); } else { writer.writeStartElement(prefix, documentRootName, nameSpaceURI); writer.writeNamespace(prefix, nameSpaceURI); } return writer; } }
XMLWriterUtil { public static XMLStreamWriter startDocument(ByteArrayOutputStream outputStream, String prefix, String documentRootName, String nameSpaceURI) throws XMLStreamException { XMLStreamWriter writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(outputStream, UTF_8.name()); if (isNullOrEmpty(prefix)) { writer.writeStartElement(documentRootName); writer.setDefaultNamespace(nameSpaceURI); writer.writeDefaultNamespace(nameSpaceURI); } else { writer.writeStartElement(prefix, documentRootName, nameSpaceURI); writer.writeNamespace(prefix, nameSpaceURI); } return writer; } private  XMLWriterUtil(); }
XMLWriterUtil { public static XMLStreamWriter startDocument(ByteArrayOutputStream outputStream, String prefix, String documentRootName, String nameSpaceURI) throws XMLStreamException { XMLStreamWriter writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(outputStream, UTF_8.name()); if (isNullOrEmpty(prefix)) { writer.writeStartElement(documentRootName); writer.setDefaultNamespace(nameSpaceURI); writer.writeDefaultNamespace(nameSpaceURI); } else { writer.writeStartElement(prefix, documentRootName, nameSpaceURI); writer.writeNamespace(prefix, nameSpaceURI); } return writer; } private  XMLWriterUtil(); static String getPropertyXmlForPrimitives(String rootName, Type type, Object data, String context); static XMLStreamWriter getPropertyXmlForPrimitivesStartDocument(
            String rootName, Type type, Object data, String context, OutputStream outputStream); static void getPropertyXmlForPrimitivesBodyDocument(
            String rootName, Type type, Object data, XMLStreamWriter xmlStreamWriter); static void getPropertyXmlForPrimitivesEndDocument(
            String rootName, Type type, Object data, XMLStreamWriter xmlStreamWriter); static XMLStreamWriter startDocument(ByteArrayOutputStream outputStream,
                                                String prefix, String documentRootName, String nameSpaceURI); static void endDocument(XMLStreamWriter writer); static XMLStreamWriter startElement(OutputStream outputStream, String rootName, String typeName,
                                               String context, boolean defaultNameSpace); static void writePrimitiveElement(XMLStreamWriter writer, String nodeName, Object nodeValue); static void writePrimitiveCollection(XMLStreamWriter writer, String nodeName, List values); static void writeElementWithNull(XMLStreamWriter writer, String nodeName); static void endElement(XMLStreamWriter writer); static String getNullPropertyXML(String rootName, String context); }
XMLWriterUtil { public static XMLStreamWriter startDocument(ByteArrayOutputStream outputStream, String prefix, String documentRootName, String nameSpaceURI) throws XMLStreamException { XMLStreamWriter writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(outputStream, UTF_8.name()); if (isNullOrEmpty(prefix)) { writer.writeStartElement(documentRootName); writer.setDefaultNamespace(nameSpaceURI); writer.writeDefaultNamespace(nameSpaceURI); } else { writer.writeStartElement(prefix, documentRootName, nameSpaceURI); writer.writeNamespace(prefix, nameSpaceURI); } return writer; } private  XMLWriterUtil(); static String getPropertyXmlForPrimitives(String rootName, Type type, Object data, String context); static XMLStreamWriter getPropertyXmlForPrimitivesStartDocument(
            String rootName, Type type, Object data, String context, OutputStream outputStream); static void getPropertyXmlForPrimitivesBodyDocument(
            String rootName, Type type, Object data, XMLStreamWriter xmlStreamWriter); static void getPropertyXmlForPrimitivesEndDocument(
            String rootName, Type type, Object data, XMLStreamWriter xmlStreamWriter); static XMLStreamWriter startDocument(ByteArrayOutputStream outputStream,
                                                String prefix, String documentRootName, String nameSpaceURI); static void endDocument(XMLStreamWriter writer); static XMLStreamWriter startElement(OutputStream outputStream, String rootName, String typeName,
                                               String context, boolean defaultNameSpace); static void writePrimitiveElement(XMLStreamWriter writer, String nodeName, Object nodeValue); static void writePrimitiveCollection(XMLStreamWriter writer, String nodeName, List values); static void writeElementWithNull(XMLStreamWriter writer, String nodeName); static void endElement(XMLStreamWriter writer); static String getNullPropertyXML(String rootName, String context);  }