sbol-data-io-RDF/src/main/java/org/sbolstandard/core/io/rdf/RdfIo.java
public IoWriter<QName> createIoWriter(final XMLStreamWriter writer)
  {
    return new IoWriter<QName>() {

      @Override
      public void write(DocumentRoot<QName> document) throws CoreIoException {
        try
        {
          writer.writeStartDocument();

          writeStartElement(RDF);
          setPrefix(rdf);

          if(!document.getNamespaceBindings().contains(rdf)) {
            writeNamespace(rdf);
          }

          for(NamespaceBinding nb : document.getNamespaceBindings()) {
            setPrefix(nb);
            writeNamespace(nb);
          }

          for (TopLevelDocument<QName> child : document.getTopLevelDocuments())
          {
            write(child);
          }

          writer.writeEndElement();
          writer.writeEndDocument();
        }
        catch(XMLStreamException xse)
        {
          throw new CoreIoException(xse);
        }

      }

      private void write(IdentifiableDocument<QName> doc) throws XMLStreamException {
        writeStartElement(doc.getType());
        writeAttribute(rdfAbout, doc.getIdentity().toString());

        for (NamedProperty<QName> property : doc.getProperties()) {
          write(property);
        }

        writer.writeEndElement();
      }

      private void write(final NamedProperty<QName> property) {
        new PropertyValue.Visitor<QName>() {
          @Override
          public void visit(NestedDocument<QName> v) throws XMLStreamException {
            writeStartElement(property.getName());
            write(v);
            writer.writeEndElement();
          }

          @Override
          public void visit(Literal<QName> v) throws XMLStreamException {
            if(isEmptyElementValue(v)) {
              writeEmptyElement(property.getName());
              write(v);
            } else {
              writeStartElement(property.getName());
              write(v);
              writer.writeEndElement();
            }
          }
        }.visit(property.getValue());
      }

      private boolean isEmptyElementValue(Literal<QName> literal) {
        return /* literal instanceof Literal.QNameLiteral || */ literal instanceof Literal.UriLiteral;
      }

      private void write(Literal<QName> literal) {
        new Literal.Visitor<QName>() {
          @Override
          public void visit(Literal.StringLiteral<QName> l) throws XMLStreamException {
            writer.writeCharacters(l.getValue());
          }

          @Override
          public void visit(Literal.UriLiteral<QName> l) throws XMLStreamException {
            writeAttribute(rdfResource, l.getValue().toString());
          }

          @Override
          public void visit(Literal.IntegerLiteral<QName> l) throws XMLStreamException {
            writer.writeCharacters(l.getValue().toString());
          }

          @Override
          public void visit(Literal.DoubleLiteral<QName> l) throws XMLStreamException {
            writer.writeCharacters(l.getValue().toString());
          }

          @Override
          public void visit(Literal.TypedLiteral<QName> l) throws XMLStreamException {
            writer.writeCharacters(l.getValue() + "^^" + l.getType().getPrefix() + ":" + l.getType().getLocalPart());
          }

          @Override
          public void visit(Literal.BooleanLiteral<QName> l) throws XMLStreamException {
            writer.writeCharacters(l.getValue().toString());
          }
        }.visit(literal);
      }

      private void writeEmptyElement(QName tagName) throws XMLStreamException {
        writer.writeEmptyElement(tagName.getPrefix(), tagName.getLocalPart(), tagName.getNamespaceURI());
      }

      private void writeStartElement(QName tagName) throws XMLStreamException {
        writer.writeStartElement(tagName.getPrefix(), tagName.getLocalPart(), tagName.getNamespaceURI());
      }

      private void setPrefix(NamespaceBinding binding) throws XMLStreamException {
        writer.setPrefix(binding.getPrefix(), binding.getNamespaceURI());
      }

      private void writeNamespace(NamespaceBinding binding) throws XMLStreamException {
        writer.writeNamespace(binding.getPrefix(), binding.getNamespaceURI());
      }

      private void writeAttribute(QName attrName, String attrValue) throws XMLStreamException {
        writer.writeAttribute(
                attrName.getPrefix(),
                attrName.getNamespaceURI(),
                attrName.getLocalPart(),
                attrValue);
      }

    };
  }
public IoWriter<QName> createIoWriter(final XMLStreamWriter writer)
  {
    return new IoWriter<QName>() {

      @Override
      public void write(DocumentRoot<QName> document) throws CoreIoException {
        try
        {
          writer.writeStartDocument();

          writeStartElement(RDF);
          setPrefix(rdf);

          if(!document.getNamespaceBindings().contains(rdf)) {
            writeNamespace(rdf);
          }

          for(NamespaceBinding nb : document.getNamespaceBindings()) {
            setPrefix(nb);
            writeNamespace(nb);
          }

          for (TopLevelDocument<QName> child : document.getTopLevelDocuments())
          {
            write(child);
          }

          writer.writeEndElement();
          writer.writeEndDocument();
        }
        catch(XMLStreamException xse)
        {
          throw new CoreIoException(xse);
        }

      }

      private void write(IdentifiableDocument<QName> doc) throws XMLStreamException {
        writeStartElement(doc.getType());
        writeAttribute(rdfAbout, doc.getIdentity().toString());

        for (NamedProperty<QName> property : doc.getProperties()) {
          write(property);
        }

        writer.writeEndElement();
      }

      private void write(final NamedProperty<QName> property) {
        new PropertyValue.Visitor<QName>() {
          @Override
          public void visit(NestedDocument<QName> v) throws XMLStreamException {
            writeStartElement(property.getName());
            write(v);
            writer.writeEndElement();
          }

          @Override
          public void visit(Literal<QName> v) throws XMLStreamException {
            if(isEmptyElementValue(v)) {
              writeEmptyElement(property.getName());
              write(v);
            } else {
              writeStartElement(property.getName());
              write(v);
              writer.writeEndElement();
            }
          }
        }.visit(property.getValue());
      }

      private boolean isEmptyElementValue(Literal<QName> literal) {
        return /* literal instanceof Literal.QNameLiteral || */ literal instanceof Literal.UriLiteral;
      }

      private void write(Literal<QName> literal) {
        new Literal.Visitor<QName>() {
          @Override
          public void visit(Literal.StringLiteral<QName> l) throws XMLStreamException {
            writer.writeCharacters(l.getValue());
          }

          @Override
          public void visit(Literal.UriLiteral<QName> l) throws XMLStreamException {
            writeAttribute(rdfResource, l.getValue().toString());
          }

          @Override
          public void visit(Literal.IntegerLiteral<QName> l) throws XMLStreamException {
            writer.writeCharacters(l.getValue().toString());
          }

          @Override
          public void visit(Literal.DoubleLiteral<QName> l) throws XMLStreamException {
            writer.writeCharacters(l.getValue().toString());
          }

          @Override
          public void visit(Literal.TypedLiteral<QName> l) throws XMLStreamException {
            writer.writeCharacters(l.getValue() + "^^" + l.getType().getPrefix() + ":" + l.getType().getLocalPart());
          }

          @Override
          public void visit(Literal.BooleanLiteral<QName> l) throws XMLStreamException {
            writer.writeCharacters(l.getValue().toString());
          }
        }.visit(literal);
      }

      private void writeEmptyElement(QName tagName) throws XMLStreamException {
        writer.writeEmptyElement(tagName.getPrefix(), tagName.getLocalPart(), tagName.getNamespaceURI());
      }

      private void writeStartElement(QName tagName) throws XMLStreamException {
        writer.writeStartElement(tagName.getPrefix(), tagName.getLocalPart(), tagName.getNamespaceURI());
      }

      private void setPrefix(NamespaceBinding binding) throws XMLStreamException {
        writer.setPrefix(binding.getPrefix(), binding.getNamespaceURI());
      }

      private void writeNamespace(NamespaceBinding binding) throws XMLStreamException {
        writer.writeNamespace(binding.getPrefix(), binding.getNamespaceURI());
      }

      private void writeAttribute(QName attrName, String attrValue) throws XMLStreamException {
        writer.writeAttribute(
                attrName.getPrefix(),
                attrName.getNamespaceURI(),
                attrName.getLocalPart(),
                attrValue);
      }

    };
  }
Creates an {@link IoWriter} using the given {@link XMLStreamWriter} object.

<p>This {@link IoWriter} provides a method to write {@link DocumentRoot} objects in RDF/XML format.
During the serialisation, the RDF namespace is added if it is not provided in the {@link NamespaceBinding}s property of a {@link DocumentRoot}.
</p>
@param writer The {@link XMLStreamWriter} writer to serialise a {@link DocumentRoot}.
@return {@link IoWriter}