def write_document(document, out, validate=True):
if validate:<EOL><INDENT>messages = []<EOL>messages = document.validate(messages)<EOL>if messages:<EOL><INDENT>raise InvalidDocumentError(messages)<EOL><DEDENT><DEDENT>writer = Writer(document, out)<EOL>writer.write()<EOL>
Write an SPDX RDF document.
- document - spdx.document instance.
- out - file like object that will be written to.
Optionally `validate` the document before writing and raise
InvalidDocumentError if document.validate returns False.