# Parsers in Raptor (syntax to triples)

## Introduction

This section describes the parsers that can be compiled into Raptor and their options. The exact parsers supported may vary by different builds of raptor and can be queried at run-time by use of the `raptor_world_get_parser_description` function

The options that may be set on parsers can also be queried at run-time with the `raptor_world_get_option_description` function.

## GRDDL parser (name `grddl`)

A parser for the Gleaning Resource Descriptions from Dialects of Languages (GRDDL), W3C Proposed Recommendation of 2007-07-16 which allows reading XHTML and XML as RDF triples by using profiles in the document that declare XSLT transforms from the XHTML or XML content into RDF/XML or other RDF syntax which can then be parsed.

The GRDDL parser is rather complex and different from the other parsers in that it retrieves URIs, reads HTML documents (possibly with errors), transforms the documents with XSLT and turns the result into a single graph. The default configuration of the GRDDL parser also reads microformats (hcard, hcalendar) and follows <link> tags that point to RDF/XML. Parts of the GRDDL process can be altered by configuration, which are describe below.

The GRDDL parser defines 'base', 'Base' and 'url' XSLT parameters with the value of the base URI to allow some XSLT sheets to work. These set of parameters cannot be disabled.

If the XSLT transform returns an empty string, no further processing of the result is done, and a warning is generated. The xsl:output method is mapped to result document mime types as follows: 'text' to text/plain; 'xml' to application/xml and 'html' to text/html. Any result that is of type 'application/xml' or unknown mime type is assumed to be RDF/XML.

The URIs that are processed during GRDDL operations can be checked and skipped if required using a handler set with the `raptor_parser_set_uri_filter()` function. If the handler returns non-0, the URI is rejected. This uses `raptor_www_set_uri_filter()` internally.

If the value of option `RAPTOR_OPTION_WWW_TIMEOUT` if set to a number >0, it is used as the timeout in seconds for retrieving of URIs during GRDDL processing. This uses `raptor_www_set_connection_timeout()` internally.

The hardcoded support for hcard and hcalendar microformats can be disabled by setting parser option `RAPTOR_OPTION_MICROFORMATS` to 0 or using `raptor_parser_set_option()` with option `RAPTOR_OPTION_STRICT` and a boolean value of 1.

The GRDDL parser by default will try an XML parser on the content followed by a lax HTML parser. This can be disabled by setting parser option `RAPTOR_OPTION_HTML_TAG_SOUP` to 0 or using `raptor_parser_set_option()` with option `RAPTOR_OPTION_STRICT` and a boolean value of 1.

The GRDDL parser by default will try to look for an HTML <link> tag that points to RDF/XML. This can be disabled by setting parser option `RAPTOR_OPTION_HTML_LINK` to 0 or using `raptor_parser_set_option()` with option `RAPTOR_OPTION_STRICT` and a boolean value of 1.

## Guess parser (name `guess`)

This is a special parser that picks the actual parser to use based on the content type, the content bytes or the content identifier. The content name can be either from a local file or from a URI.

If the protocol that delivered the content (such as HTTP) provided a Content Type (aka MIME Type) then this will be the primary means for identifying th ecotnent.

The secondary means to identify the content are the bytes of the content (if available), otherwise the content identifier is used, which is the least reliable.

## JSON parser (name `json`)

A parser for both the resource-centric RDF/JSON syntax as defined by Talis at RDF/JSON Specification and the triples-centric format based on the SPARQL results in JSON format.

## N-Triples parser (name `ntriples`)

A parser for the N-Triples syntax as used by the W3C RDF Core working group for the RDF Test Cases.

## RDFa parser - (name `rdfa`)

A parser for the RDFa syntax, W3C Candidate Recommendation 20 June 2008 which allows reading XHTML and XML as RDF triples by interpreting attributes on elements to describe which ones have RDF semantics. This is implemented via librdfa linked inside Raptor, written by Manu Sporny of Digital Bazaar, and licensed with the same license as Raptor.

This parser is beta quality and passes all but 4 of the RDFa tests as of Raptor 1.4.18.

## RDF/XML parser - default (name `rdfxml`)

A parser for the standard RDF/XML syntax as revised by the W3C RDF Core working group.

This is the default parser in Raptor.

Features of this parser:

- Fully handles the RDF/XML syntax updates for XML Base, `xml:lang`, RDF datatyping and Collections.

- Handles all RDF vocabularies such as FOAF, RSS 1.0, Dublin Core, OWL, DOAP

- Handles `rdf:resource` / `resource` attributes

- Uses expat and/or (GNOME) libxml XML parsers as available or required

## RSS Tag Soup parser (name `rss-tag-soup`)

A parser for the multiple XML RSS formats that use the elements such as `channel`, `item`, `title`, `description` in different ways. This includes support for the Atom 1.0 syndication format defined in IETF RFC 4287

The parser attempts to turn the input into RSS 1.0 RDF triples in the RSS 1.0 model of a syndication feed. This includes triples for RSS Enclosures.

True RSS 1.0 when wanted to be used as a full RDF vocabulary, is best parsed by the RDF/XML parser (name `rdfxml`).

## TRiG parser (name `trig`)

A parser for the TriG - Turtle with Named Graphs syntax.

The parser is alpha quality and may not support the entire TRiG specification.

## Turtle Terse RDF Triple Language parser (name `turtle`)

A parser for the Turtle Terse RDF Triple Language syntax, designed as a useful subset of Notation 3.