private byte[] ser(final String xml, final SerializerVocabulary serializerVocabulary)
            throws IOException, SAXException, ParserConfigurationException {

        final SAXParserFactory factory = SAXParserFactory.newInstance();
        factory.setNamespaceAware(true);
        final SAXParser saxParser = factory.newSAXParser();

        ByteArrayOutputStream os;
        try (final Reader reader = new StringReader(xml)) {
            try (final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) {
                os = byteArrayOutputStream;
                final SAXDocumentSerializer saxDocumentSerializer = new SAXDocumentSerializer();
                saxDocumentSerializer.setOutputStream(byteArrayOutputStream);
                if (serializerVocabulary != null) {
//                    saxDocumentSerializer.setVocabulary(createSerializerVocabulary(vocabulary));
//                    saxDocumentSerializer.setVocabulary(createSerializerVocabulary(vocabulary));
                    // Not quite sure why we have to set our serializerVocabulary as an externalVocab on
                    // a new SerializerVocabulary.
                    final SerializerVocabulary serializerVocabularyLocal = new SerializerVocabulary();
                    serializerVocabularyLocal.setExternalVocabulary(URI, serializerVocabulary, false);
//                    serializerVocabulary = createSerializerVocabulary(vocabulary);
//                    serializerVocabulary.setExternalVocabulary(
//                            URI, createSerializerVocabulary(vocabulary), false);
                    saxDocumentSerializer.setVocabulary(serializerVocabularyLocal);
//                    dumpVocab(vocabulary, "Pre ser input vocab");
//                    dumpVocab(vocabulary, "Pre ser serialiser vocab");
                }

                LOGGER.info("Serialise xml");
                saxParser.parse(new InputSource(reader), saxDocumentSerializer);

//                if (vocabulary != null) {
//                    dumpVocab(vocabulary, "Post ser input vocab");
//                    dumpVocab(vocabulary, "Post ser serialiser vocab");
//                }
            }
        }

        final byte[] fastInfosetBytes = os.toByteArray();

        LOGGER.info("Serialising {} bytes of XML to {} bytes", xml.getBytes().length, fastInfosetBytes.length);
        return fastInfosetBytes;
    }
A proof of concept for https://github.com/gchq/stroom/issues/1945
Trying to prove that we can generate a fast infoset vocab
for some xml and then append to it. This is to reduce the volume of data
stored in the LMDB ref data store.
stroom-pipeline/src/test/java/stroom/pipeline/refdata/TestFastInfosetVocab.java