Пример #1
0
static void
rasqal_query_write_sparql_uri(sparql_writer_context *wc,
                              raptor_iostream* iostr, raptor_uri* uri)
{
  size_t len;
  unsigned char* string;
  raptor_qname* qname;

  qname = raptor_new_qname_from_namespace_uri(wc->nstack, uri, 10);
  if(qname) {
    const raptor_namespace* nspace = raptor_qname_get_namespace(qname);
    if(!raptor_namespace_get_prefix(nspace))
      raptor_iostream_write_byte(':', iostr);
    raptor_qname_write(qname, iostr);
    raptor_free_qname(qname);
    return;
  }
  
  if(wc->base_uri)
    string = raptor_uri_to_relative_counted_uri_string(wc->base_uri, uri, &len);
  else
    string = raptor_uri_as_counted_string(uri, &len);

  raptor_iostream_write_byte('<', iostr);
  raptor_string_ntriples_write(string, len, '>', iostr);
  raptor_iostream_write_byte('>', iostr);

  if(wc->base_uri)
    raptor_free_memory(string);
}
Пример #2
0
static void raptor_rdfa_end_element(void *user_data,
                                    raptor_xml_element* xml_element)
{
  raptor_qname* qname = raptor_xml_element_get_name(xml_element);
  unsigned char* localname = raptor_qname_to_counted_name(qname, NULL);
  const raptor_namespace* qname_ns = raptor_qname_get_namespace(qname);

  if(qname_ns)
    end_element(user_data, (const char*)localname,
                (const char*)qname_ns->prefix,
                (const xmlChar*)raptor_uri_as_string(qname_ns->uri));
  else
    end_element(user_data, (const char*)localname, NULL, NULL);

  raptor_free_memory(localname);
}
Пример #3
0
static void raptor_rdfa_start_element(void *user_data,
                                      raptor_xml_element *xml_element)
{
  raptor_qname* qname = raptor_xml_element_get_name(xml_element);
  int nb_attributes = raptor_xml_element_get_attributes_count(xml_element);
  raptor_qname** attrs = raptor_xml_element_get_attributes(xml_element);
  unsigned char* localname = raptor_qname_to_counted_name(qname, NULL);
  const raptor_namespace* qname_ns = raptor_qname_get_namespace(qname);
  int nb_namespaces = 0;
  const char** namespaces = NULL;
  int nb_defaulted = 0;
  char** attr = NULL;
  int i;
  const char* ns_name = NULL;
  const char* ns_uri = NULL;

  if(nb_attributes > 0) {
    /* Everything written into 'attr' is a shared pointer into
     * xml_element or contained objects - qnames, namespaces, uris
     * and values
     */
    attr = (char**)malloc(sizeof(char*) * (1 + (nb_attributes * 5)));
    for(i = 0; i < nb_attributes; i++) {
      const raptor_namespace* attr_ns = attrs[i]->nspace;
      char** attri = &attr[5 * i];
      /* 5 tuple: (localname, prefix, URI, value, end) */
      attri[0] = (char*)attrs[i]->local_name;
      attri[1] = attr_ns ? (char*)attr_ns->prefix : NULL;
      attri[2] = attr_ns ? (char*)raptor_uri_as_string(attr_ns->uri) : NULL;
      attri[3] = (char*)attrs[i]->value;
      attri[4] = attri[3] + attrs[i]->value_length;
    }
    attr[5 * i] = NULL;
  }

/*
 * @ctx:  the user data (XML parser context)
 * @localname:  the local name of the element
 * @prefix:  the element namespace prefix if available
 * @URI:  the element namespace name if available
 * @nb_namespaces:  number of namespace definitions on that node
 * @namespaces:  pointer to the array of prefix/URI pairs namespace definitions
 * @nb_attributes:  the number of attributes on that node
 * @nb_defaulted:  the number of defaulted attributes. The defaulted
 *                  ones are at the end of the array
 * @attributes:  pointer to the array of (localname/prefix/URI/value/end)
 *               attribute values.
 */
  if(qname_ns) {
    ns_name = (const char*)raptor_namespace_get_prefix(qname_ns);
    ns_uri = (const char*)raptor_uri_as_string(qname_ns->uri);
  }

  start_element(user_data, (const char*)localname,
                ns_name,
                ns_uri,
                nb_namespaces,
                (const char**)namespaces,
                nb_attributes,
                nb_defaulted,
                (const char**)attr);
  if(attr)
    free(attr);
  raptor_free_memory(localname);
}