/** * raptor_valid_xml_ID: * @rdf_parser: RDF parser * @string: The string to check. * * Check the string matches the xml:ID value constraints. * * This checks the syntax part of the xml:ID validity constraint, * that it matches [ VC: Name Token ] as amended by XML Namespaces: * * See <ulink url="http://www.w3.org/TR/REC-xml-names/#NT-NCName">Namespaces in XML NCName<ulink> * * Return value: non-zero if the ID string is valid **/ int raptor_valid_xml_ID(raptor_parser *rdf_parser, const unsigned char *string) { size_t len = strlen((const char*)string); #ifdef RAPTOR_XML_1_1 #define XML_ID_XML_VERSION 11 #else #define XML_ID_XML_VERSION 10 #endif return raptor_xml_name_check(string, len, XML_ID_XML_VERSION); }
/* * raptor_new_qname_from_resource: * @namespaces: sequence of namespaces (corresponding to nstack) * @nstack: #raptor_namespace_stack to use/update * @namespace_count: size of nstack (may be modified) * @node: #raptor_abbrev_node to use * * Make an XML QName from the URI associated with the node. * * Return value: the QName or NULL on failure **/ raptor_qname* raptor_new_qname_from_resource(raptor_sequence* namespaces, raptor_namespace_stack* nstack, int* namespace_count, raptor_abbrev_node* node) { unsigned char* name=NULL; /* where to split predicate name */ size_t name_len=1; unsigned char *uri_string; size_t uri_len; unsigned char c; unsigned char *p; raptor_uri *ns_uri; raptor_namespace *ns; raptor_qname *qname; if(node->type != RAPTOR_IDENTIFIER_TYPE_RESOURCE) { RAPTOR_FATAL1("Node must be a resource\n"); return NULL; } qname=raptor_namespaces_qname_from_uri(nstack, node->value.resource.uri, 10); if(qname) return qname; uri_string = raptor_uri_as_counted_string(node->value.resource.uri, &uri_len); p= uri_string; name_len=uri_len; while(name_len >0) { if(raptor_xml_name_check(p, name_len, 10)) { name=p; break; } p++; name_len--; } if(!name || (name == uri_string)) return NULL; c=*name; *name='\0'; ns_uri=raptor_new_uri(uri_string); if(!ns_uri) return NULL; *name=c; ns = raptor_namespaces_find_namespace_by_uri(nstack, ns_uri); if(!ns) { /* The namespace was not declared, so create one */ unsigned char prefix[2 + MAX_ASCII_INT_SIZE + 1]; *namespace_count = *namespace_count + 1; sprintf((char *)prefix, "ns%d", *namespace_count); ns = raptor_new_namespace_from_uri(nstack, prefix, ns_uri, 0); /* We'll most likely need this namespace again. Push it on our * stack. It will be deleted in * raptor_rdfxmla_serialize_terminate */ if(raptor_sequence_push(namespaces, ns)) { /* namespaces sequence has no free handler so we have to free the ns ourselves on error */ raptor_free_namespace(ns); raptor_free_uri(ns_uri); return NULL; } } qname = raptor_new_qname_from_namespace_local_name(ns, name, NULL); raptor_free_uri(ns_uri); return qname; }