Exemplo n.º 1
0
static void
rasqal_rowsource_sparql_xml_process(rasqal_rowsource_sparql_xml_context* con)
{
  if(raptor_sequence_size(con->results_sequence) && con->variables_count > 0)
    return;

  /* do some parsing - need some results */
  while(!raptor_iostream_read_eof(con->iostr)) {
    size_t read_len;
    
    read_len = raptor_iostream_read_bytes((char*)con->buffer, 1,
                                          FILE_READ_BUF_SIZE,
                                          con->iostr);
    if(read_len > 0) {
      RASQAL_DEBUG2("processing %d bytes\n", (int)read_len);
      raptor_sax2_parse_chunk(con->sax2, con->buffer, read_len, 0);
      con->locator.byte += read_len;
    }
    
    if(read_len < FILE_READ_BUF_SIZE) {
      /* finished */
      raptor_sax2_parse_chunk(con->sax2, NULL, 0, 1);
      break;
    }
    
    /* end with variables sequence done AND at least one row */
    if(con->variables_count > 0 &&
       raptor_sequence_size(con->results_sequence) > 0)
      break;
  }
  
}
Exemplo n.º 2
0
int rdfa_parse_chunk(rdfacontext* context, char* data, size_t wblen, int done)
{
#ifdef LIBRDFA_IN_RAPTOR
#else
   xmlSAXHandler handler;
   xmlParserCtxtPtr parser;
#endif

   /* it is an error to call this before rdfa_parse_start() */
   if(context->done)
   {
      return RDFA_PARSE_FAILED;
   }

   if(!context->preread)
   {
      /* search for the <base> tag and use the href contained therein to
       * set the parsing context. */
      context->wb_preread = rdfa_init_base(context,
         &context->working_buffer, &context->wb_allocated, data, wblen);

      /* continue looking if in first 131072 bytes of data */
      if(!context->base && context->wb_preread < (1<<17))
         return RDFA_PARSE_SUCCESS;

#ifdef LIBRDFA_IN_RAPTOR
      /* term mappings are needed before SAX2 parsing */
      rdfa_setup_initial_context(context);

      if(raptor_sax2_parse_chunk(context->sax2,
                                 (const unsigned char*)context->working_buffer,
                                 context->wb_position, done))
      {
         return RDFA_PARSE_FAILED;
      }
#else
      /* create the SAX2 handler structure */
      memset(&handler, 0, sizeof(xmlSAXHandler));
      handler.initialized = XML_SAX2_MAGIC;
      handler.startElementNs = (startElementNsSAX2Func)start_element;
      handler.endElementNs = (endElementNsSAX2Func)end_element;
      handler.characters = (charactersSAXFunc)character_data;
      handler.error = (errorSAXFunc)rdfa_report_error;

      /* create a push-based parser */
      parser = xmlCreatePushParserCtxt(
         &handler, context, (const char*)context->working_buffer,
         context->wb_position, NULL);

      /* ensure that entity substitution is turned on by default */
      xmlSubstituteEntitiesDefault(1);

      context->parser = parser;

      rdfa_setup_initial_context(context);
#endif

      context->preread = 1;

      return RDFA_PARSE_SUCCESS;
   }

   /* otherwise just parse the block passed in */
#ifdef LIBRDFA_IN_RAPTOR
   if(raptor_sax2_parse_chunk(context->sax2,
                              (const unsigned char*)data, wblen, done))
   {
      return RDFA_PARSE_FAILED;
   }
#else
   if(xmlParseChunk(context->parser, data, wblen, done))
   {
      return RDFA_PARSE_FAILED;
   }
#endif

   return RDFA_PARSE_SUCCESS;
}