code: @Override
      public void writeXML(Document xml) {
          writeAMF3();
          buf.put(AMF3.TYPE_XML);
          if (hasReference(xml)) {
              putInteger(getReferenceId(xml) << 1);
              return;
          }
          final byte[] encoded = encodeString(XMLUtils.docToString(xml));
          putInteger(encoded.length << 1 | 1);
          buf.put(encoded);
          storeReference(xml);
      }
docs: {@inheritDoc}