Provide a destination for the serialized syntax

The operation of turning RDF triples into a syntax has several alternatives from functions that do most of the work writing to a file or string to functions that allow passing in a raptor_iostream which can be entirely user-constructed.

Serialize to a filename (raptor_serialize_start_to_filename())

Serialize to a new filename (using raptor_new_iostream_to_filename() internally) and uses asf base URI, the file's URI.

  const char *filename="raptor.rdf";
  raptor_serialize_start_to_filename(rdf_serializer, filename);

Serialize to a string (raptor_serialize_start_to_string())

Serialize to a string that is allocated by the serializer (using raptor_new_iostream_to_string() internally). The resulting string is only constructed after raptor_serialize_end() is called and at that point it is assigned to the string pointer passed in, with the length written to the optional length pointer. This function takes an optional base URI but may be required by some serializers.

  raptor_uri* uri=raptor_new_uri("http://example.org/base");
  void *string;  /* destination for string */
  size_t length; /* length of constructed string */

  raptor_serialize_start_to_string(rdf_serializer, uri,
                                   &string, &length);

Serialize to a FILE* file handle (raptor_serialize_start_to_file_handle())

Serialize to an existing open C FILE* file handle (using raptor_new_iostream_to_file_handle() internally). The handle is not closed after serializing is finished. This function takes an optional base URI but may be required by some serializers.

  raptor_uri* uri=raptor_new_uri("http://example.org/base");
  FILE* fh=fopen("raptor.rdf", "wb");
  raptor_serialize_start_to_file_handle(rdf_serializer, uri, fh);

This is the most flexible serializing method as it allows writing to any raptor_iostream which can be constructed to build any form of user-generated structure via callbacks. The iostream remains owned by the caller that can continue to write to it after the serializing is finished (after raptor_serialize_end()) is called).

  raptor_uri* uri=raptor_new_uri("http://example.org/base");
  raptor_iostream* iostream = /* iostream initialized by some means */ ;

  raptor_serialize_start_to_iostream(rdf_serializer, uri, iostream);

  while( /* got RDF triples */ ) {
    raptor_statement* triple = /* ... triple made from somewhere ... */ ;
    raptor_serialize_statement(rdf_serializer,  triple);
  }
  raptor_serialize_end(rdf_serializer);

  raptor_free_serializer(rdf_serializer);

  /* ... write other stuff to iostream ... */

  raptor_free_iostream(iostream);

Serialize to an raptor_iostream and close iostream (raptor_serialize_start())

raptor_serialize_start() also serializes to an iostream like raptor_serialize_start_to_iostream() but it becomes the owner of the passed in raptor_iostream and destroys it at the end of serializing, so no further use of the iostream can be made by the caller.