docs: public static void writeKeydef(final File keydefFile, final Collection<KeyDef> keydefs) throws DITAOTException {
          XMLStreamWriter keydef = null;
          try (OutputStream out = new FileOutputStream(keydefFile)) {
              keydef = XMLOutputFactory.newInstance().createXMLStreamWriter(out, "UTF-8");
              keydef.writeStartDocument();
              keydef.writeStartElement(ELEMENT_STUB);
              for (final KeyDef k : keydefs) {
                  keydef.writeStartElement(ELEMENT_KEYDEF);
                  keydef.writeAttribute(ATTRIBUTE_KEYS, k.keys);
                  if (k.href != null) {
                      keydef.writeAttribute(ATTRIBUTE_HREF, k.href.toString());
                  }
                  if (k.scope != null) {
                      keydef.writeAttribute(ATTRIBUTE_SCOPE, k.scope);
                  }
                  if (k.format != null) {
                      keydef.writeAttribute(ATTRIBUTE_FORMAT, k.format);
                  }
                  if (k.source != null) {
                      keydef.writeAttribute(ATTRIBUTE_SOURCE, k.source.toString());
                  }
                  keydef.writeEndElement();
              }
              keydef.writeEndDocument();
          } catch (final XMLStreamException | IOException e) {
              throw new DITAOTException("Failed to write key definition file " + keydefFile + ": " + e.getMessage(), e);
          } finally {
              if (keydef != null) {
                  try {
                      keydef.close();
                  } catch (final XMLStreamException e) {
                  }
              }
          }
      }