Redland
view release on metacpan or search on metacpan
redland/raptor/src/raptor_sax2.c view on Meta::CPAN
return sax2;
}
void
raptor_free_sax2(raptor_sax2 *sax2) {
raptor_xml_element *xml_element;
#ifdef RAPTOR_XML_EXPAT
if(sax2->xp) {
XML_ParserFree(sax2->xp);
sax2->xp=NULL;
}
#endif
#ifdef RAPTOR_XML_LIBXML
if(sax2->xc) {
raptor_libxml_free(sax2->xc);
sax2->xc=NULL;
}
#endif
while( (xml_element=raptor_xml_element_pop(sax2)) )
raptor_free_xml_element(xml_element);
raptor_namespaces_clear(&sax2->namespaces);
if(sax2->base_uri)
raptor_free_uri(sax2->base_uri);
RAPTOR_FREE(raptor_sax2, sax2);
}
void
raptor_sax2_set_start_element_handler(raptor_sax2* sax2,
raptor_sax2_start_element_handler handler)
{
sax2->start_element_handler=handler;
}
void
raptor_sax2_set_end_element_handler(raptor_sax2* sax2,
raptor_sax2_end_element_handler handler)
{
sax2->end_element_handler=handler;
}
void
raptor_sax2_set_characters_handler(raptor_sax2* sax2,
raptor_sax2_characters_handler handler)
{
sax2->characters_handler=handler;
}
void
raptor_sax2_set_cdata_handler(raptor_sax2* sax2,
raptor_sax2_cdata_handler handler)
{
sax2->cdata_handler=handler;
}
void
raptor_sax2_set_comment_handler(raptor_sax2* sax2,
raptor_sax2_comment_handler handler)
{
sax2->comment_handler=handler;
}
void
raptor_sax2_set_unparsed_entity_decl_handler(raptor_sax2* sax2,
raptor_sax2_unparsed_entity_decl_handler handler)
{
sax2->unparsed_entity_decl_handler=handler;
}
void
raptor_sax2_set_external_entity_ref_handler(raptor_sax2* sax2,
raptor_sax2_external_entity_ref_handler handler)
{
sax2->external_entity_ref_handler=handler;
}
/**
* raptor_sax2_set_namespace_handler:
* @parser: #raptor_sax2 object
* @user_data: user data pointer for callback
* @handler: new namespace callback function
*
* 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.
*
**/
void
raptor_sax2_set_namespace_handler(raptor_sax2* sax2,
raptor_namespace_handler handler)
{
sax2->namespace_handler=handler;
}
void
raptor_sax2_set_locator(raptor_sax2* sax2, raptor_locator* locator)
{
sax2->locator=locator;
}
raptor_xml_element*
raptor_xml_element_pop(raptor_sax2 *sax2)
{
raptor_xml_element *element=sax2->current_element;
if(!element)
return NULL;
sax2->current_element=element->parent;
if(sax2->root_element == element) /* just deleted root */
sax2->root_element=NULL;
return element;
}
void
raptor_xml_element_push(raptor_sax2 *sax2, raptor_xml_element* element)
{
element->parent=sax2->current_element;
sax2->current_element=element;
if(!sax2->root_element)
sax2->root_element=element;
}
/**
* raptor_xml_element_is_empty:
* @xml_element: XML Element
*
* Check if an XML Element is empty.
*
* Return value: non-0 if the element is empty.
**/
int
raptor_xml_element_is_empty(raptor_xml_element* xml_element)
{
return !xml_element->content_cdata_seen &&
!xml_element->content_element_seen;
}
const unsigned char*
raptor_sax2_inscope_xml_language(raptor_sax2 *sax2)
{
raptor_xml_element* xml_element;
for(xml_element=sax2->current_element;
xml_element;
xml_element=xml_element->parent)
if(xml_element->xml_language)
return xml_element->xml_language;
return NULL;
}
raptor_uri*
raptor_sax2_inscope_base_uri(raptor_sax2 *sax2)
{
raptor_xml_element *xml_element;
for(xml_element=sax2->current_element;
xml_element;
xml_element=xml_element->parent)
if(xml_element->base_uri)
return xml_element->base_uri;
return sax2->base_uri;
}
int
raptor_sax2_get_depth(raptor_sax2 *sax2)
{
return sax2->depth;
}
void
raptor_sax2_inc_depth(raptor_sax2 *sax2)
{
sax2->depth++;
}
void
raptor_sax2_dec_depth(raptor_sax2 *sax2)
{
sax2->depth--;
}
static void raptor_sax2_simple_error(void* user_data, const char *message, ...) RAPTOR_PRINTF_FORMAT(2, 3);
/*
* raptor_sax2_simple_error - Error from a sax2 - Internal
*
* Matches the raptor_simple_message_handler API but calls
* the sax2 error_handler
redland/raptor/src/raptor_sax2.c view on Meta::CPAN
sax2->start_element_handler(sax2->user_data, xml_element);
if(xml_atts_copy) {
/* Restore passed in XML attributes, free the copy */
memcpy((void*)atts, xml_atts_copy, xml_atts_size);
RAPTOR_FREE(cstringpointer, xml_atts_copy);
}
}
/* end of an element */
void
raptor_sax2_end_element(void* user_data, const unsigned char *name)
{
raptor_sax2* sax2=(raptor_sax2*)user_data;
raptor_xml_element* xml_element;
#ifdef RAPTOR_XML_EXPAT
#ifdef EXPAT_UTF8_BOM_CRASH
sax2->tokens_count++;
#endif
#endif
xml_element=sax2->current_element;
if(xml_element) {
#ifdef RAPTOR_DEBUG_VERBOSE
fprintf(stderr, "\nraptor_rdfxml_end_element_handler: End ns-element: ");
raptor_qname_print(stderr, xml_element->name);
fputc('\n', stderr);
#endif
if(sax2->end_element_handler)
sax2->end_element_handler(sax2->user_data, xml_element);
}
raptor_namespaces_end_for_depth(&sax2->namespaces,
raptor_sax2_get_depth(sax2));
xml_element=raptor_xml_element_pop(sax2);
if(xml_element)
raptor_free_xml_element(xml_element);
raptor_sax2_dec_depth(sax2);
}
/* characters */
void
raptor_sax2_characters(void* user_data, const unsigned char *s, int len)
{
raptor_sax2* sax2=(raptor_sax2*)user_data;
if(sax2->characters_handler)
sax2->characters_handler(sax2->user_data, sax2->current_element, s, len);
}
/* like <![CDATA[...]> */
void
raptor_sax2_cdata(void* user_data, const unsigned char *s, int len)
{
raptor_sax2* sax2=(raptor_sax2*)user_data;
#ifdef RAPTOR_XML_EXPAT
#ifdef EXPAT_UTF8_BOM_CRASH
sax2->tokens_count++;
#endif
#endif
if(sax2->cdata_handler)
sax2->cdata_handler(sax2->user_data, sax2->current_element, s, len);
}
/* comment */
void
raptor_sax2_comment(void* user_data, const unsigned char *s)
{
raptor_sax2* sax2=(raptor_sax2*)user_data;
if(sax2->comment_handler)
sax2->comment_handler(sax2->user_data, sax2->current_element, s);
}
/* unparsed (NDATA) entity */
void
raptor_sax2_unparsed_entity_decl(void* user_data,
const unsigned char* entityName,
const unsigned char* base,
const unsigned char* systemId,
const unsigned char* publicId,
const unsigned char* notationName)
{
raptor_sax2* sax2=(raptor_sax2*)user_data;
if(sax2->unparsed_entity_decl_handler)
sax2->unparsed_entity_decl_handler(sax2->user_data,
entityName, base, systemId,
publicId, notationName);
}
/* external entity reference */
int
raptor_sax2_external_entity_ref(void* user_data,
const unsigned char* context,
const unsigned char* base,
const unsigned char* systemId,
const unsigned char* publicId)
{
raptor_sax2* sax2=(raptor_sax2*)user_data;
if(sax2->external_entity_ref_handler)
return sax2->external_entity_ref_handler(sax2->user_data,
context, base, systemId, publicId);
return 0;
}
( run in 1.470 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )