section-sax2: Raptor RDF Syntax Library Manual

## section-sax2 section-sax2 |

## Functions

raptor_sax2 * | raptor_new_sax2 ()
void | raptor_free_sax2 ()
void | (*raptor_sax2_start_element_handler) ()
void | (*raptor_sax2_end_element_handler) ()
void | (*raptor_sax2_characters_handler) ()
void | (*raptor_sax2_cdata_handler) ()
void | (*raptor_sax2_comment_handler) ()
void | (*raptor_sax2_unparsed_entity_decl_handler) ()
int | (*raptor_sax2_external_entity_ref_handler) ()
void | raptor_sax2_set_start_element_handler ()
void | raptor_sax2_set_end_element_handler ()
void | raptor_sax2_set_characters_handler ()
void | raptor_sax2_set_cdata_handler ()
void | raptor_sax2_set_comment_handler ()
void | raptor_sax2_set_unparsed_entity_decl_handler ()
void | raptor_sax2_set_external_entity_ref_handler ()
void | raptor_sax2_set_namespace_handler ()
void | raptor_sax2_set_uri_filter ()
void | raptor_sax2_parse_start ()
int | raptor_sax2_parse_chunk ()
const unsigned char * | raptor_sax2_inscope_xml_language ()
raptor_uri * | raptor_sax2_inscope_base_uri ()

## Types and Values

typedef | raptor_sax2

## Description

## Functions

### raptor_new_sax2 ()

    raptor_sax2 *
    raptor_new_sax2 (raptor_world *world,
                     raptor_locator *locator,
                     void *user_data);

Constructor - Create a new SAX2 with error handlers

#### Parameters

world | raptor world |
locator | raptor locator to use for errors |
user_data | pointer context information to pass to SAX handlers |

#### Returns

new raptor_sax2 object or NULL on failure

### raptor_free_sax2 ()

    void
    raptor_free_sax2 (raptor_sax2 *sax2);

Destructor - destroy a SAX2 object

#### Parameters

sax2 | SAX2 object |

### raptor_sax2_start_element_handler ()

    void
    (*raptor_sax2_start_element_handler) (void *user_data,
                                          raptor_xml_element *xml_element);

SAX2 start element handler

#### Parameters

user_data | user data |
xml_element | XML element |

### raptor_sax2_end_element_handler ()

    void
    (*raptor_sax2_end_element_handler) (void *user_data,
                                        raptor_xml_element *xml_element);

SAX2 end element handler

#### Parameters

user_data | user data |
xml_element | XML element |

### raptor_sax2_characters_handler ()

    void
    (*raptor_sax2_characters_handler) (void *user_data,
                                       raptor_xml_element *xml_element,
                                       const char *s,
                                       int len);

SAX2 characters handler

#### Parameters

user_data | user data |
xml_element | XML element |
s | string |
len | string len |

### raptor_sax2_cdata_handler ()

    void
    (*raptor_sax2_cdata_handler) (void *user_data,
                                  raptor_xml_element *xml_element,
                                  const char *s,
                                  int len);

SAX2 CDATA section handler

#### Parameters

user_data | user data |
xml_element | XML element |
s | string |
len | string len |

### raptor_sax2_comment_handler ()

    void
    (*raptor_sax2_comment_handler) (void *user_data,
                                    raptor_xml_element *xml_element,
                                    const char *s);

SAX2 XML comment handler

#### Parameters

user_data | user data |
xml_element | XML element |
s | string |

### raptor_sax2_unparsed_entity_decl_handler ()

    void
    (*raptor_sax2_unparsed_entity_decl_handler)
                                   (void *user_data,
                                    const unsigned char *entityName,
                                    const unsigned char *base,
                                    const unsigned char *systemId,
                                    const unsigned char *publicId,
                                    const unsigned char *notationName);

SAX2 unparsed entity (NDATA) handler

#### Parameters

user_data | user data |
entityName | entity name |
base | base URI |
systemId | system ID |
publicId | public ID |
notationName | notation name |

### raptor_sax2_external_entity_ref_handler ()

    int
    (*raptor_sax2_external_entity_ref_handler)
                                   (void *user_data,
                                    const unsigned char *context,
                                    const unsigned char *base,
                                    const unsigned char *systemId,
                                    const unsigned char *publicId);

SAX2 external entity reference handler

#### Parameters

user_data | user data |
context | context |
base | base URI |
systemId | system ID |
publicId | public ID |

#### Returns

0 if processing should not continue because of a fatal error in the handling of the external entity.

### raptor_sax2_set_start_element_handler ()

    void
    raptor_sax2_set_start_element_handler (raptor_sax2 *sax2,
                                           raptor_sax2_start_element_handler handler);

Set SAX2 start element handler.

#### Parameters

sax2 | SAX2 object |
handler | start element handler |

### raptor_sax2_set_end_element_handler ()

    void
    raptor_sax2_set_end_element_handler (raptor_sax2 *sax2,
                                         raptor_sax2_end_element_handler handler);

Set SAX2 end element handler.

#### Parameters

sax2 | SAX2 object |
handler | end element handler |

### raptor_sax2_set_characters_handler ()

    void
    raptor_sax2_set_characters_handler (raptor_sax2 *sax2,
                                        raptor_sax2_characters_handler handler);

Set SAX2 characters handler.

#### Parameters

sax2 | SAX2 object |
handler | characters handler |

### raptor_sax2_set_cdata_handler ()

    void
    raptor_sax2_set_cdata_handler (raptor_sax2 *sax2,
                                   raptor_sax2_cdata_handler handler);

Set SAX2 CDATA handler.

#### Parameters

sax2 | SAX2 object |
handler | CDATA handler |

### raptor_sax2_set_comment_handler ()

    void
    raptor_sax2_set_comment_handler (raptor_sax2 *sax2,
                                     raptor_sax2_comment_handler handler);

Set SAX2 XML comment handler.

#### Parameters

sax2 | SAX2 object |
handler | comment handler |

### raptor_sax2_set_unparsed_entity_decl_handler ()

    void
    raptor_sax2_set_unparsed_entity_decl_handler
                                   (raptor_sax2 *sax2,
                                    raptor_sax2_unparsed_entity_decl_handler handler);

Set SAX2 XML unparsed entity declaration handler.

#### Parameters

sax2 | SAX2 object |
handler | unparsed entity declaration handler |

### raptor_sax2_set_external_entity_ref_handler ()

    void
    raptor_sax2_set_external_entity_ref_handler
                                   (raptor_sax2 *sax2,
                                    raptor_sax2_external_entity_ref_handler handler);

Set SAX2 XML entity reference handler.

#### Parameters

sax2 | SAX2 object |
handler | entity reference handler |

### raptor_sax2_set_namespace_handler ()

    void
    raptor_sax2_set_namespace_handler (raptor_sax2 *sax2,
                                       raptor_namespace_handler handler);

Set the XML namespace handler function.

When a prefix/namespace is seen in an XML parser, call the given `handler` with the prefix string and the raptor_uri namespace URI. Either can be NULL for the default prefix or default namespace.

The handler function does not deal with duplicates so any namespace may be declared multiple times when a namespace is seen in different parts of a document.

#### Parameters

sax2 | raptor_sax2 object |
handler | new namespace callback function |

### raptor_sax2_set_uri_filter ()

    void
    raptor_sax2_set_uri_filter (raptor_sax2 *sax2,
                                raptor_uri_filter_func filter,
                                void *user_data);

Set URI filter function for SAX2 internal retrievals.

#### Parameters

sax2 | SAX2 object |
filter | URI filter function |
user_data | User data to pass to filter function |

### raptor_sax2_parse_start ()

    void
    raptor_sax2_parse_start (raptor_sax2 *sax2,
                             raptor_uri *base_uri);

Start an XML SAX2 parse.

#### Parameters

sax2 | sax2 object |
base_uri | base URI |

### raptor_sax2_parse_chunk ()

    int
    raptor_sax2_parse_chunk (raptor_sax2 *sax2,
                             const char *buffer,
                             size_t len,
                             int is_end);

Parse a chunk of XML data generating SAX2 events

#### Parameters

sax2 | sax2 object |
buffer | input buffer |
len | input buffer lenght |
is_end | non-0 if end of data |

#### Returns

non-0 on failure

### raptor_sax2_inscope_xml_language ()

    const unsigned char *
    raptor_sax2_inscope_xml_language (raptor_sax2 *sax2);

Get the in-scope XML language

The result is a language string which may be "" if xml:lang="" is given. NULL is returned only if there is no xml:lang in any outer scope.

#### Parameters

sax2 | SAX2 object |

#### Returns

shared pointer to the XML language or NULL if none is in scope.

### raptor_sax2_inscope_base_uri ()

    raptor_uri *
    raptor_sax2_inscope_base_uri (raptor_sax2 *sax2);

Get the in-scope base URI

#### Parameters

sax2 | SAX2 object |

#### Returns

the in-scope base URI shared object or NULL if none is in scope.

## Types and Values

### raptor_sax2

    typedef struct raptor_sax2_s raptor_sax2;

Raptor SAX2 class