Parsers

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

## Synopsis

    typedef     librdf_parser;
    typedef     librdf_parser_factory;
    int         librdf_parser_enumerate         (librdf_world *world,
                                                 unsigned int counter,
                                                 const char **name,
                                                 const char **label);
    void        librdf_parser_register_factory  (librdf_world *world,
                                                 const char *name,
                                                 const char *label,
                                                 const char *mime_type,
                                                 unsigned char *uri_string,
                                                 void (*factory) (librdf_parser_factory*));
    librdf_parser* librdf_new_parser            (librdf_world *world,
                                                 const char *name,
                                                 const char *mime_type,
                                                 librdf_uri *type_uri);
    librdf_parser* librdf_new_parser_from_factory
                                                (librdf_world *world,
                                                 librdf_parser_factory *factory);
    void        librdf_free_parser              (librdf_parser *parser);
    librdf_stream* librdf_parser_parse_as_stream
                                                (librdf_parser *parser,
                                                 librdf_uri *uri,
                                                 librdf_uri *base_uri);
    int         librdf_parser_parse_into_model  (librdf_parser *parser,
                                                 librdf_uri *uri,
                                                 librdf_uri *base_uri,
                                                 librdf_model *model);
    librdf_stream* librdf_parser_parse_string_as_stream
                                                (librdf_parser *parser,
                                                 unsigned char *string,
                                                 librdf_uri *base_uri);
    int         librdf_parser_parse_string_into_model
                                                (librdf_parser *parser,
                                                 unsigned char *string,
                                                 librdf_uri *base_uri,
                                                 librdf_model *model);
    void        librdf_parser_set_error         (librdf_parser *parser,
                                                 void *user_data,
                                                 void (*error_fn) (void *user_data, const char *msg, ...));
    void        librdf_parser_set_warning       (librdf_parser *parser,
                                                 void *user_data,
                                                 void (*warning_fn) (void *user_data, const char *msg, ...));
    librdf_stream* librdf_parser_parse_counted_string_as_stream
                                                (librdf_parser *parser,
                                                 unsigned char *string,
                                                 size_t length,
                                                 librdf_uri *base_uri);
    int         librdf_parser_parse_counted_string_into_model
                                                (librdf_parser *parser,
                                                 unsigned char *string,
                                                 size_t length,
                                                 librdf_uri *base_uri,
                                                 librdf_model *model);
    #define     LIBRDF_PARSER_FEATURE_ERROR_COUNT
    #define     LIBRDF_PARSER_FEATURE_WARNING_COUNT
    librdf_node* librdf_parser_get_feature      (librdf_parser *parser,
                                                 librdf_uri *feature);
    int         librdf_parser_set_feature       (librdf_parser *parser,
                                                 librdf_uri *feature,
                                                 librdf_node *value);
    char*       librdf_parser_get_accept_header (librdf_parser *parser);

## 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.

## Details

### 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_enumerate ()

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

Get information on parsers.

`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_register_factory ()

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

Register a parser factory .

`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"

`world` : | redland world object
`name` : | the parser factory name
`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.

`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.

`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.

`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.

`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_string_as_stream ()

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

Parse a string of content to a librdf_stream of statements.

`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,
                                                 unsigned char *string,
                                                 librdf_uri *base_uri,
                                                 librdf_model *model);

Parse a string of content into an librdf_model.

`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, ...));

`Deprecated`: Does nothing

Set the parser error handling function.

`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, ...));

`Deprecated`: Does nothing.

Set the parser warning handling function.

`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,
                                                 unsigned char *string,
                                                 size_t length,
                                                 librdf_uri *base_uri);

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

`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,
                                                 unsigned char *string,
                                                 size_t length,
                                                 librdf_uri *base_uri,
                                                 librdf_model *model);

Parse a counted string of content into an librdf_model.

`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_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.

### librdf_parser_get_feature ()

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

Get the value of a parser feature.

`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.

`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 such as with `raptor_free_memory()`.

`parser` : | parser
Returns : | a new Accept: header string or NULL on failure