Ejemplo n.º 1
0
/**
 * raptor_new_sax2:
 * @world: raptor world
 * @locator: raptor locator to use for errors
 * @user_data: pointer context information to pass to SAX handlers
 *
 * Constructor - Create a new SAX2 with error handlers
 *
 * Return value: new #raptor_sax2 object or NULL on failure
 */
raptor_sax2*
raptor_new_sax2(raptor_world *world, raptor_locator *locator,
                void* user_data)
{
  raptor_sax2* sax2;

  RAPTOR_CHECK_CONSTRUCTOR_WORLD(world);

  if(!locator)
    return NULL;
  
  raptor_world_open(world);

  sax2 = RAPTOR_CALLOC(raptor_sax2*, 1, sizeof(*sax2));
  if(!sax2)
    return NULL;

#ifdef RAPTOR_XML_LIBXML
  sax2->magic = RAPTOR_LIBXML_MAGIC;
#endif

  sax2->world = world;
  sax2->locator = locator;
  sax2->user_data = user_data;

  sax2->enabled = 1;

  raptor_object_options_init(&sax2->options, RAPTOR_OPTION_AREA_SAX2);
  
  return sax2;
}
Ejemplo n.º 2
0
/**
 * raptor_new_xml_writer:
 * @world: raptor_world object
 * @nstack: Namespace stack for the writer to start with (or NULL)
 * @iostr: I/O stream to write to
 * 
 * Constructor - Create a new XML Writer writing XML to a raptor_iostream
 * 
 * Return value: a new #raptor_xml_writer object or NULL on failure
 **/
raptor_xml_writer*
raptor_new_xml_writer(raptor_world* world,
                      raptor_namespace_stack *nstack,
                      raptor_iostream* iostr)
{
  raptor_xml_writer* xml_writer;

  RAPTOR_CHECK_CONSTRUCTOR_WORLD(world);

  if(!iostr)
    return NULL;
  
  raptor_world_open(world);

  xml_writer = (raptor_xml_writer*)RAPTOR_CALLOC(raptor_xml_writer, 1,
                                                 sizeof(*xml_writer));
  if(!xml_writer)
    return NULL;

  xml_writer->world = world;

  xml_writer->nstack_depth = 0;

  xml_writer->nstack = nstack;
  if(!xml_writer->nstack) {
    xml_writer->nstack = raptor_new_namespaces(world, 1);
    xml_writer->my_nstack = 1;
  }

  xml_writer->iostr = iostr;

  raptor_object_options_init(&xml_writer->options,
                             RAPTOR_OPTION_AREA_XML_WRITER);
  
  RAPTOR_OPTIONS_SET_NUMERIC(xml_writer, RAPTOR_OPTION_WRITER_INDENT_WIDTH, 2);
  
  RAPTOR_OPTIONS_SET_NUMERIC(xml_writer, RAPTOR_OPTION_WRITER_XML_VERSION, 10);

  /* Write XML declaration */
  RAPTOR_OPTIONS_SET_NUMERIC(xml_writer, RAPTOR_OPTION_WRITER_XML_DECLARATION, 1);
  
  return xml_writer;
}
Ejemplo n.º 3
0
/**
 * raptor_new_serializer:
 * @world: raptor_world object
 * @name: the serializer name or NULL for default syntax
 *
 * Constructor - create a new raptor_serializer object.
 *
 * Return value: a new #raptor_serializer object or NULL on failure
 */
raptor_serializer*
raptor_new_serializer(raptor_world* world, const char *name)
{
  raptor_serializer_factory* factory;
  raptor_serializer* rdf_serializer;

  RAPTOR_CHECK_CONSTRUCTOR_WORLD(world);

  raptor_world_open(world);

  factory = raptor_get_serializer_factory(world, name);
  if(!factory)
    return NULL;

  rdf_serializer = RAPTOR_CALLOC(raptor_serializer*, 1, sizeof(*rdf_serializer));
  if(!rdf_serializer)
    return NULL;

  rdf_serializer->world = world;
  
  rdf_serializer->context = RAPTOR_CALLOC(void*, 1, factory->context_length);
  if(!rdf_serializer->context) {
    raptor_free_serializer(rdf_serializer);
    return NULL;
  }
  
  rdf_serializer->factory = factory;

  raptor_object_options_init(&rdf_serializer->options,
                             RAPTOR_OPTION_AREA_SERIALIZER);

  if(factory->init(rdf_serializer, name)) {
    raptor_free_serializer(rdf_serializer);
    return NULL;
  }
  
  return rdf_serializer;
}