| Raptor RDF Syntax Parsing and Serializing Library Manual |
|---|
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.
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_guess_parser_name()
for a full discussion of the inputs to the guessing.
raptor_parse_uri())The URI is resolved and the content read from it and passed to the parser:
raptor_parse_uri(rdf_parser, uri, base_uri);
The base_uri is optional (can be
NULL) and will default to the
uri.
raptor_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_www_new_with_connection
for full details of how this works. The content is then read from the
result of resolving the URI:
raptor_parse_uri_with_connection(rdf_parser, uri, base_uri, connection);
The base_uri is optional (can be
NULL) and will default to the
uri.
FILE* (raptor_parse_file_stream())Parsing can read from a C STDIO file handle:
stream=fopen(filename, "rb"); raptor_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.
raptor_parse_file())Parsing can read from a URI known to be a file: URI:
raptor_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.
raptor_start_parse() and raptor_parse_chunk())
raptor_start_parse(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_parse_chunk(rdf_parser, buffer, buffer_len, 0);
}
raptor_parse_chunk(rdf_parser, NULL, 0, 1); /* no data and is_end = 1 */
The base_uri argument to
raptor_start_parse()
may be required by some parsers
and if NULL will cause the parsing to fail.
On the last
raptor_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_start_parse(rdf_parser, base_uri); raptor_parse_chunk(rdf_parser, buffer, buffer_len, 1); /* is_end = 1 */