Provide syntax content to parse

The operation of turning syntax into RDF triples has several alternatives from functions that do most of the work starting from a URI to functions that allow passing in data buffers.

Parsing and MIME Types

The mime type of the retrieved content is not used to choose a parser unless the parser is of type guess. The guess parser will send an Accept: header for all known parser syntax mime types (if a URI request is made) and based on the response, including the identifiers used, pick the appropriate parser to execute. See raptor_world_guess_parser_name() for a full discussion of the inputs to the guessing.

Parse the content from a URI (raptor_parser_parse_uri())

The URI is resolved and the content read from it and passed to the parser:

  raptor_parser_parse_uri(rdf_parser, uri, base_uri);

The base_uri is optional (can be NULL) and will default to the uri.

Parse the content of a URI using an existing WWW connection (raptor_parser_parse_uri_with_connection())

The URI is resolved using an existing WWW connection (for example a libcurl CURL handle) to allow for any existing WWW configuration to be reused. See raptor_new_www_with_connection for full details of how this works. The content is then read from the result of resolving the URI:

  raptor_parser_parse_uri_with_connection(rdf_parser, uri, base_uri, connection);

The base_uri is optional (can be NULL) and will default to the uri.

Parse the content of a C FILE* (raptor_parser_parse_file_stream())

Parsing can read from a C STDIO file handle:

  stream = fopen(filename, "rb");
  raptor_parser_parse_file_stream(rdf_parser, stream, filename, base_uri);
  fclose(stream);

This function can use take an optional filename which is used in locator error messages. The base_uri may be required by some parsers and if NULL will cause the parsing to fail. This requirement can be checked by looking at the flags in the parser description using raptor_world_get_parser_description().

Parse the content of a file URI (raptor_parser_parse_file())

Parsing can read from a URI known to be a file: URI:

  raptor_parser_parse_file(rdf_parser, file_uri, base_uri);

This function requires that the file_uri is a file URI, that is raptor_uri_uri_string_is_file_uri( raptor_uri_as_string( file_uri) ) must be true. The base_uri may be required by some parsers and if NULL will cause the parsing to fail.

Parse chunks of syntax content provided by the application (raptor_parser_parse_start() and raptor_parser_parse_chunk())

  raptor_parser_parse_start(rdf_parser, base_uri);
  while(/* not finished getting content */) {
    unsigned char *buffer;
    size_t buffer_len;

    /* ... obtain some syntax content in buffer of size buffer_len bytes ... */

    raptor_parser_parse_chunk(rdf_parser, buffer, buffer_len, 0);
  }
  raptor_parser_parse_chunk(rdf_parser, NULL, 0, 1); /* no data and is_end = 1 */

The base_uri argument to raptor_parser_parse_start() may be required by some parsers and if NULL will cause the parsing to fail.

On the last raptor_parser_parse_chunk() call, or after the loop is ended, the is_end parameter must be set to non-0. Content can be passed with the final call. If no content is present at the end (such as in some kind of end of file situation), then a 0-length buffer_len or NULL buffer can be used.

The minimal case is an entire parse in one chunk as follows:

  raptor_parser_parse_start(rdf_parser, base_uri);
  raptor_parser_parse_chunk(rdf_parser, buffer, buffer_len, 1); /* is_end = 1 */


Navigation: Redland Home Page

Copyright 2000-2014 Dave Beckett