## Parsers Parsers — RDF parsers from syntax to triples. |

## Functions

int | librdf_parser_check_name ()
const raptor_syntax_description * | librdf_parser_get_description ()
int | librdf_parser_enumerate ()
const char * | librdf_parser_guess_name ()
const char * | librdf_parser_guess_name2 ()
void | librdf_parser_register_factory ()
librdf_parser * | librdf_new_parser ()
librdf_parser * | librdf_new_parser_from_factory ()
void | librdf_free_parser ()
librdf_stream * | librdf_parser_parse_as_stream ()
int | librdf_parser_parse_into_model ()
librdf_stream * | librdf_parser_parse_file_handle_as_stream ()
int | librdf_parser_parse_file_handle_into_model ()
librdf_stream * | librdf_parser_parse_string_as_stream ()
int | librdf_parser_parse_string_into_model ()
void | librdf_parser_set_error ()
void | librdf_parser_set_warning ()
librdf_stream * | librdf_parser_parse_counted_string_as_stream ()
int | librdf_parser_parse_counted_string_into_model ()
librdf_stream * | librdf_parser_parse_iostream_as_stream ()
int | librdf_parser_parse_iostream_into_model ()
librdf_node * | librdf_parser_get_feature ()
int | librdf_parser_set_feature ()
char * | librdf_parser_get_accept_header ()
int | librdf_parser_get_namespaces_seen_count ()
const char * | librdf_parser_get_namespaces_seen_prefix ()
librdf_uri * | librdf_parser_get_namespaces_seen_uri ()
librdf_uri_filter_func | librdf_parser_get_uri_filter ()
void | librdf_parser_set_uri_filter ()

## Types and Values

typedef | librdf_parser
typedef | librdf_parser_factory
#define | LIBRDF_PARSER_FEATURE_ERROR_COUNT
#define | LIBRDF_PARSER_FEATURE_WARNING_COUNT

## Description

Provides classes to create parsers and parse syntaxes from URIs or a string into RDF graphs (librdf_model) or sequences of triples (librdf_stream). Parser features can be set, which are passed down to Raptor and errors and warnings that are returned can be retrieved by callbacks.

## Functions

### librdf_parser_check_name ()

    int
    librdf_parser_check_name (librdf_world *world,
                              const char *name);

Check if a parser name is known

#### Parameters

world | redland world object |
name | name of parser |

#### Returns

non 0 if name is a known parser

### librdf_parser_get_description ()

    const raptor_syntax_description *
    librdf_parser_get_description (librdf_world *world,
                                   unsigned int counter);

Get parser descriptive syntax information

#### Parameters

world | world object |
counter | index into the list of parsers |

#### Returns

description or NULL if counter is out of range

### librdf_parser_enumerate ()

    int
    librdf_parser_enumerate (librdf_world *world,
                             const unsigned int counter,
                             const char **name,
                             const char **label);

`librdf_parser_enumerate` is deprecated and should not be used in newly-written code.

Get information on parsers.

`Deprecated` : use `librdf_parser_get_description()` to return more information in a static structure.

#### Parameters

world | redland world object |
counter | index into the list of parsers |
name | pointer to store the name of the parser (or NULL) |
label | pointer to store syntax readable label (or NULL) |

#### Returns

non 0 on failure of if counter is out of range

### librdf_parser_guess_name ()

    const char *
    librdf_parser_guess_name (const char *mime_type,
                              const unsigned char *buffer,
                              const unsigned char *identifier);

`librdf_parser_guess_name` is deprecated and should not be used in newly-written code.

Get a parser name for content with type or identifier

#### Parameters

mime_type | MIME type of syntax or NULL |
buffer | content buffer or NULL |
identifier | content identifier or NULL |

#### Returns

a parser name or NULL if nothing was guessable

### librdf_parser_guess_name2 ()

    const char *
    librdf_parser_guess_name2 (librdf_world *world,
                               const char *mime_type,
                               const unsigned char *buffer,
                               const unsigned char *identifier);

Get a parser name for content with type or identifier

#### Parameters

world | librdf_world object |
mime_type | MIME type of syntax or NULL |
buffer | content buffer or NULL |
identifier | content identifier or NULL |

#### Returns

a parser name or NULL if nothing was guessable

### librdf_parser_register_factory ()

    void
    librdf_parser_register_factory (librdf_world *world,
                                    const char *name,
                                    const char *label,
                                    const char *mime_type,
                                    const unsigned char *uri_string,
                                    void (*factory) (librdf_parser_factory*));

Register a parser factory .

#### Parameters

world | redland world object |
name | the name of the parser |
label | the label of the parser (optional) |
mime_type | MIME type of the syntax (optional) |
uri_string | URI of the syntax (optional) |
factory | function to be called to register the factor parameters |

### librdf_new_parser ()

    librdf_parser *
    librdf_new_parser (librdf_world *world,
                       const char *name,
                       const char *mime_type,
                       librdf_uri *type_uri);

Constructor - create a new librdf_parser object.

If all fields are NULL, this means any parser supporting MIME Type "application/rdf+xml"

#### Parameters

world | redland world object |
name | the parser factory name (or NULL or empty string if don't care) |
mime_type | the MIME type of the syntax (NULL if not used) |
type_uri | URI of syntax (NULL if not used) |

#### Returns

new librdf_parser object or NULL

### librdf_new_parser_from_factory ()

    librdf_parser *
    librdf_new_parser_from_factory (librdf_world *world,
                                    librdf_parser_factory *factory);

Constructor - create a new librdf_parser object.

#### Parameters

world | redland world object |
factory | the parser factory to use to create this parser |

#### Returns

new librdf_parser object or NULL

### librdf_free_parser ()

    void
    librdf_free_parser (librdf_parser *parser);

Destructor - destroys a librdf_parser object.

#### Parameters

parser | the parser |

### librdf_parser_parse_as_stream ()

    librdf_stream *
    librdf_parser_parse_as_stream (librdf_parser *parser,
                                   librdf_uri *uri,
                                   librdf_uri *base_uri);

Parse a URI to a librdf_stream of statements.

#### Parameters

parser | the parser |
uri | the URI to read |
base_uri | the base URI to use or NULL |

#### Returns

librdf_stream of statements or NULL

### librdf_parser_parse_into_model ()

    int
    librdf_parser_parse_into_model (librdf_parser *parser,
                                    librdf_uri *uri,
                                    librdf_uri *base_uri,
                                    librdf_model *model);

Parse a URI of content into an librdf_model.

#### Parameters

parser | the parser |
uri | the URI to read the content |
base_uri | the base URI to use or NULL |
model | the model to use |

#### Returns

non 0 on failure

### librdf_parser_parse_file_handle_as_stream ()

    librdf_stream *
    librdf_parser_parse_file_handle_as_stream
                                   (librdf_parser *parser,
                                    FILE *fh,
                                    int close_fh,
                                    librdf_uri *base_uri);

Parse a FILE* handle of content to a librdf_stream of statements.

#### Parameters

parser | the parser |
fh | FILE* to read content source |
close_fh | non-0 to `fclose()` the file handle on finishing |
base_uri | the base URI to use (or NULL) |

#### Returns

librdf_stream of statements or NULL

### librdf_parser_parse_file_handle_into_model ()

    int
    librdf_parser_parse_file_handle_into_model
                                   (librdf_parser *parser,
                                    FILE *fh,
                                    int close_fh,
                                    librdf_uri *base_uri,
                                    librdf_model *model);

Parse a FILE* handle of content into an librdf_model.

#### Parameters

parser | the parser |
fh | FILE* to read content source |
close_fh | non-0 to `fclose()` the file handle on finishing |
base_uri | the base URI to use (or NULL) |
model | the model to write to |

#### Returns

non 0 on failure

### librdf_parser_parse_string_as_stream ()

    librdf_stream *
    librdf_parser_parse_string_as_stream (librdf_parser *parser,
                                          const unsigned char *string,
                                          librdf_uri *base_uri);

Parse a string of content to a librdf_stream of statements.

#### Parameters

parser | the parser |
string | the string to parse |
base_uri | the base URI to use or NULL |

#### Returns

librdf_stream of statements or NULL

### librdf_parser_parse_string_into_model ()

    int
    librdf_parser_parse_string_into_model (librdf_parser *parser,
                                           const unsigned char *string,
                                           librdf_uri *base_uri,
                                           librdf_model *model);

Parse a string of content into an librdf_model.

#### Parameters

parser | the parser |
string | the content to parse |
base_uri | the base URI to use or NULL |
model | the model to use |

#### Returns

non 0 on failure

### librdf_parser_set_error ()

    void
    librdf_parser_set_error (librdf_parser *parser,
                             void *user_data,
                             void (*error_fn) (void *user_data, const char *msg, ...));

`librdf_parser_set_error` is deprecated and should not be used in newly-written code.

`Deprecated` : Does nothing

Set the parser error handling function.

#### Parameters

parser | the parser |
user_data | user data to pass to function |
error_fn | pointer to the function |

### librdf_parser_set_warning ()

    void
    librdf_parser_set_warning (librdf_parser *parser,
                               void *user_data,
                               void (*warning_fn) (void *user_data, const char *msg, ...));

`librdf_parser_set_warning` is deprecated and should not be used in newly-written code.

`Deprecated` : Does nothing.

Set the parser warning handling function.

#### Parameters

parser | the parser |
user_data | user data to pass to function |
warning_fn | pointer to the function |

### librdf_parser_parse_counted_string_as_stream ()

    librdf_stream *
    librdf_parser_parse_counted_string_as_stream
                                   (librdf_parser *parser,
                                    const unsigned char *string,
                                    size_t length,
                                    librdf_uri *base_uri);

Parse a counted string of content to a librdf_stream of statements.

#### Parameters

parser | the parser |
string | the string to parse |
length | length of the string content (must be >0) |
base_uri | the base URI to use or NULL |

#### Returns

librdf_stream of statements or NULL

### librdf_parser_parse_counted_string_into_model ()

    int
    librdf_parser_parse_counted_string_into_model
                                   (librdf_parser *parser,
                                    const unsigned char *string,
                                    size_t length,
                                    librdf_uri *base_uri,
                                    librdf_model *model);

Parse a counted string of content into an librdf_model.

#### Parameters

parser | the parser |
string | the content to parse |
length | length of content (must be >0) |
base_uri | the base URI to use or NULL |
model | the model to use |

#### Returns

non 0 on failure

### librdf_parser_parse_iostream_as_stream ()

    librdf_stream *
    librdf_parser_parse_iostream_as_stream
                                   (librdf_parser *parser,
                                    raptor_iostream *iostream,
                                    librdf_uri *base_uri);

Parse an iostream of content to a librdf_stream of statements.

#### Parameters

parser | the parser |
iostream | the iostream to parse |
base_uri | the base URI to use or NULL |

#### Returns

librdf_stream of statements or NULL

### librdf_parser_parse_iostream_into_model ()

    int
    librdf_parser_parse_iostream_into_model
                                   (librdf_parser *parser,
                                    raptor_iostream *iostream,
                                    librdf_uri *base_uri,
                                    librdf_model *model);

Parse a iostream of content into an librdf_model.

#### Parameters

parser | the parser |
iostream | the content to parse |
base_uri | the base URI to use or NULL |
model | the model to use |

#### Returns

non 0 on failure

### librdf_parser_get_feature ()

    librdf_node *
    librdf_parser_get_feature (librdf_parser *parser,
                               librdf_uri *feature);

Get the value of a parser feature.

#### Parameters

parser | librdf_parser object |
feature | librdf_Uuri feature property |

#### Returns

new librdf_node feature value or NULL if no such feature exists or the value is empty.

### librdf_parser_set_feature ()

    int
    librdf_parser_set_feature (librdf_parser *parser,
                               librdf_uri *feature,
                               librdf_node *value);

Set the value of a parser feature.

#### Parameters

parser | librdf_parser object |
feature | librdf_uri feature property |
value | librdf_node feature property value |

#### Returns

non 0 on failure (negative if no such feature)

### librdf_parser_get_accept_header ()

    char *
    librdf_parser_get_accept_header (librdf_parser *parser);

Get an HTTP Accept value for the parser.

The returned string must be freed by the caller using `librdf_free_memory()`.

#### Parameters

parser | parser |

#### Returns

a new Accept: header string or NULL on failure

### librdf_parser_get_namespaces_seen_count ()

    int
    librdf_parser_get_namespaces_seen_count
                                   (librdf_parser *parser);

Get the number of namespaces seen during parsing

#### Parameters

parser | librdf_parser object |

#### Returns

namespace count

### librdf_parser_get_namespaces_seen_prefix ()

    const char *
    librdf_parser_get_namespaces_seen_prefix
                                   (librdf_parser *parser,
                                    int offset);

Get the prefix of namespaces seen during parsing

#### Parameters

parser | librdf_parser object |
offset | index into list of namespaces |

#### Returns

prefix or NULL if no such namespace prefix

### librdf_parser_get_namespaces_seen_uri ()

    librdf_uri *
    librdf_parser_get_namespaces_seen_uri (librdf_parser *parser,
                                           int offset);

Get the uri of namespaces seen during parsing

#### Parameters

parser | librdf_parser object |
offset | index into list of namespaces |

#### Returns

uri or NULL if no such namespace uri

### librdf_parser_get_uri_filter ()

    librdf_uri_filter_func
    librdf_parser_get_uri_filter (librdf_parser *parser,
                                  void **user_data_p);

Get the current URI filter function for retrieval during parsing.

#### Parameters

parser | librdf_parser object |
user_data_p | Pointer to user data to return |

#### Returns

current URI filter function

### librdf_parser_set_uri_filter ()

    void
    librdf_parser_set_uri_filter (librdf_parser *parser,
                                  librdf_uri_filter_func filter,
                                  void *user_data);

Set URI filter function for retrieval during parsing.

#### Parameters

parser | librdf_parser object |
filter | URI filter function |
user_data | User data to pass to filter function |

## Types and Values

### librdf_parser

    typedef struct librdf_parser_s librdf_parser;

Redland parser class.

### librdf_parser_factory

    typedef struct librdf_parser_factory_s librdf_parser_factory;

Redland parser factory class.

### LIBRDF_PARSER_FEATURE_ERROR_COUNT

    #define LIBRDF_PARSER_FEATURE_ERROR_COUNT "http://feature.librdf.org/parser-error-count"

Parser feature URI string for getting the error count of the last parse.

### LIBRDF_PARSER_FEATURE_WARNING_COUNT

    #define LIBRDF_PARSER_FEATURE_WARNING_COUNT "http://feature.librdf.org/parser-warning-count"

Parser feature URI string for getting the warning count of the last parse.