void EB_Msg__initWithDoc(EB_MSG *m) { xmlNodePtr rootNode; const char *s; assert(m); m->xpathCtx=xmlXPathNewContext(m->doc); if (xmlXPathRegisterNs(m->xpathCtx, BAD_CAST "ds", BAD_CAST "http://www.w3.org/2000/09/xmldsig#")!= 0) { DBG_ERROR(AQEBICS_LOGDOMAIN, "Unable to register NS"); abort(); } if (xmlXPathRegisterNs(m->xpathCtx, BAD_CAST "xsi", BAD_CAST "http://www.w3.org/2001/XMLSchema-instance")!= 0) { DBG_ERROR(AQEBICS_LOGDOMAIN, "Unable to register NS"); abort(); } if (m->hVersion==NULL) { rootNode=xmlDocGetRootElement(m->doc); s=(const char*)xmlGetProp(rootNode, BAD_CAST "Version"); if (!(s && *s)) s="H000"; free(m->hVersion); m->hVersion=strdup(s); } }
/* Add iwb name spaces to the xmlXPathContext. */ static xmlXPathContextPtr register_namespaces (xmlXPathContextPtr context) { xmlXPathRegisterNs (context, (xmlChar *) "iwb", (xmlChar *) "http://www.becta.org.uk/iwb"); xmlXPathRegisterNs (context, (xmlChar *) "xlink", (xmlChar *) "http://www.w3.org/1999/xlink"); xmlXPathRegisterNs (context, (xmlChar *) "svg", (xmlChar *) "http://www.w3.org/2000/svg"); return context; }
void linphone_xml_xpath_context_init_carddav_ns(xmlparsing_context_t *xml_ctx) { if (xml_ctx && xml_ctx->xpath_ctx) { xmlXPathRegisterNs(xml_ctx->xpath_ctx, (const xmlChar*)"d", (const xmlChar*)"DAV:"); xmlXPathRegisterNs(xml_ctx->xpath_ctx, (const xmlChar*)"card", (const xmlChar*)"urn:ietf:params:xml:ns:carddav"); xmlXPathRegisterNs(xml_ctx->xpath_ctx, (const xmlChar*)"x1", (const xmlChar*)"http://calendarserver.org/ns/"); } }
/** * xmlSchematronNewValidCtxt: * @schema: a precompiled XML Schematrons * @options: a set of xmlSchematronValidOptions * * Create an XML Schematrons validation context based on the given schema. * * Returns the validation context or NULL in case of error */ xmlSchematronValidCtxtPtr xmlSchematronNewValidCtxt(xmlSchematronPtr schema, int options) { int i; xmlSchematronValidCtxtPtr ret; ret = (xmlSchematronValidCtxtPtr) xmlMalloc(sizeof(xmlSchematronValidCtxt)); if (ret == NULL) { xmlSchematronVErrMemory(NULL, "allocating validation context", NULL); return (NULL); } memset(ret, 0, sizeof(xmlSchematronValidCtxt)); ret->type = XML_STRON_CTXT_VALIDATOR; ret->schema = schema; ret->xctxt = xmlXPathNewContext(NULL); ret->flags = options; if (ret->xctxt == NULL) { xmlSchematronPErrMemory(NULL, "allocating schema parser XPath context", NULL); xmlSchematronFreeValidCtxt(ret); return (NULL); } for (i = 0;i < schema->nbNamespaces;i++) { if ((schema->namespaces[2 * i] == NULL) || (schema->namespaces[2 * i + 1] == NULL)) break; xmlXPathRegisterNs(ret->xctxt, schema->namespaces[2 * i + 1], schema->namespaces[2 * i]); } return (ret); }
/** * Registers the specified namespaces with an XML XPath context. * * @param xpath_context - a pointer to a xmlXPathContext structure * @param namespaces - a list of namespaces, containing two elements * for every namespace: a prefix, and a href (in that order). * @return 0 on success, -1 otherwise */ int libxml_xpath_register_namespaces(xmlXPathContextPtr xpath_context, struct wb_str_list *namespaces) { struct wb_str_list *current_ns = namespaces; char *prefix, *href; int res; while (current_ns != NULL) { prefix = current_ns->str; current_ns = current_ns->next; if (current_ns != NULL) { href = current_ns->str; current_ns = current_ns->next; } else { return -1; } res = xmlXPathRegisterNs(xpath_context, BAD_CAST prefix, BAD_CAST href); if (res != 0) { return -1; } } return 0; }
/** * @brief Get list of \<collectingPrecoess\>es from user configuration. * @param doc User XML configuration. * @return List of \<collectingProcess\> nodes in the form of XPath objects, NULL * in case of error. */ xmlXPathObjectPtr get_collectors(xmlDocPtr doc) { xmlXPathObjectPtr retval = NULL; xmlXPathContextPtr context = NULL; /* create xpath evaluation context */ if ((context = xmlXPathNewContext(doc)) == NULL) { return NULL; } /* register namespace */ if (xmlXPathRegisterNs(context, BAD_CAST "ietf-ipfix", BAD_CAST "urn:ietf:params:xml:ns:yang:ietf-ipfix-psamp") != 0) { return NULL; } /* search for collectingProcess nodes defining collectors */ if ((retval = xmlXPathEvalExpression(BAD_CAST "/ietf-ipfix:ipfix/ietf-ipfix:collectingProcess", context)) != NULL) { if (xmlXPathNodeSetIsEmpty(retval->nodesetval)) { xmlXPathFreeObject(retval); retval = NULL; } } /* Cleanup of XPath data */ xmlXPathFreeContext(context); return (retval); }
/** * \brief Initiate internal configuration file - open, get xmlDoc and prepare * XPathContext. Also register namespace "urn:cesnet:params:xml:ns:yang:ipfixcol-internals" * with given namespace name. * * @param[in] ns_name Name for the "urn:cesnet:params:xml:ns:yang:ipfixcol-internals" * namespace in xpath queries. * @return XPath Context for the internal XML configuration. Caller will need to * free it including separated free of return->doc. */ static xmlXPathContextPtr ic_init(xmlChar* ns_name, char *internal_cfg) { int fd; xmlDocPtr doc = NULL; xmlXPathContextPtr ctxt = NULL; /* open and prepare internal XML configuration file */ if ((fd = open(internal_cfg, O_RDONLY)) == -1) { MSG_ERROR(msg_module, "Unable to open internal configuration file %s (%s)", internal_cfg, strerror(errno)); return (NULL); } if ((doc = xmlReadFd(fd, NULL, NULL, XML_PARSE_NOERROR | XML_PARSE_NOWARNING | XML_PARSE_NOBLANKS)) == NULL) { MSG_ERROR(msg_module, "Unable to parse internal configuration file %s", internal_cfg); close(fd); return (NULL); } close(fd); /* create xpath evaluation context of internal configuration file */ if ((ctxt = xmlXPathNewContext(doc)) == NULL) { MSG_ERROR(msg_module, "Unable to create XPath context for internal configuration (%s:%d)", __FILE__, __LINE__); xmlFreeDoc(doc); return (NULL); } /* register namespace for the context of internal configuration file */ if (xmlXPathRegisterNs (ctxt, ns_name, BAD_CAST "urn:cesnet:params:xml:ns:yang:ipfixcol-internals") != 0) { MSG_ERROR(msg_module, "Unable to register namespace for internal configuration file (%s:%d)", __FILE__, __LINE__); xmlXPathFreeContext(ctxt); xmlFreeDoc(doc); return (NULL); } return (ctxt); }
/* * Class: org_xmlsoft_XPathContext * Method: addNamespaceImpl * Signature: (Ljava/lang/String;Ljava/lang/String;)V */ JNIEXPORT void JNICALL Java_org_xmlsoft_XPathContext_addNamespaceImpl (JNIEnv *env, jobject obj, jstring jPrefix, jstring jHref) { xmlXPathContext *ctx = findXPathContext(env, obj); const char *prefix = NULL; const char *href = NULL; int ret; if( jPrefix!=NULL ) prefix = (*env)->GetStringUTFChars(env, jPrefix, NULL); if( jHref!=NULL ) href = (*env)->GetStringUTFChars(env, jHref, NULL); ret = xmlXPathRegisterNs(ctx, (const xmlChar*)prefix, (const xmlChar*)href); if( jPrefix!=NULL ) (*env)->ReleaseStringUTFChars(env, jPrefix, prefix); if( jHref!=NULL ) (*env)->ReleaseStringUTFChars(env, jHref, href); if( ret ) { if(!throwInternalErrorWithLastError(env)) { throwInternalErrorWithMessage(env, "xmlXPathRegisterNs"); } } }
#include "RS_XML.h" #include <libxml/xpath.h> #include "Utils.h" static SEXP convertNodeSetToR(xmlNodeSetPtr obj, SEXP fun, int encoding, SEXP manageMemory) { SEXP ans, expr = NULL, arg = NULL, ref; int i; if(!obj) return(NULL_USER_OBJECT); PROTECT(ans = NEW_LIST(obj->nodeNr)); if(GET_LENGTH(fun) && (TYPEOF(fun) == CLOSXP || TYPEOF(fun) == BUILTINSXP)) { PROTECT(expr = allocVector(LANGSXP, 2)); SETCAR(expr, fun); arg = CDR(expr); } else if(TYPEOF(fun) == LANGSXP) { expr = fun; arg = CDR(expr); } for(i = 0; i < obj->nodeNr; i++) { xmlNodePtr el; el = obj->nodeTab[i]; if(el->type == XML_ATTRIBUTE_NODE) { #if 0 PROTECT(ref = mkString((el->children && el->children->content) ? XMLCHAR_TO_CHAR(el->children->content) : "")); SET_NAMES(ref, mkString(el->name)); #else PROTECT(ref = ScalarString(mkCharCE((el->children && el->children->content) ? XMLCHAR_TO_CHAR(el->children->content) : "", encoding))); SET_NAMES(ref, ScalarString(mkCharCE(el->name, encoding))); #endif SET_CLASS(ref, mkString("XMLAttributeValue")); UNPROTECT(1); } else if(el->type == XML_NAMESPACE_DECL) ref = R_createXMLNsRef((xmlNsPtr) el); else ref = R_createXMLNodeRef(el, manageMemory); if(expr) { PROTECT(ref); SETCAR(arg, ref); PROTECT(ref = Rf_eval(expr, R_GlobalEnv)); /*XXX do we want to catch errors here? Maybe to release the namespaces. */ SET_VECTOR_ELT(ans, i, ref); UNPROTECT(2); } else SET_VECTOR_ELT(ans, i, ref); } if(expr) { if(TYPEOF(fun) == CLOSXP || TYPEOF(fun) == BUILTINSXP) UNPROTECT(1); } else SET_CLASS(ans, mkString("XMLNodeSet")); UNPROTECT(1); return(ans); } SEXP convertXPathObjectToR(xmlXPathObjectPtr obj, SEXP fun, int encoding, SEXP manageMemory) { SEXP ans = NULL_USER_OBJECT; switch(obj->type) { case XPATH_NODESET: ans = convertNodeSetToR(obj->nodesetval, fun, encoding, manageMemory); break; case XPATH_BOOLEAN: ans = ScalarLogical(obj->boolval); break; case XPATH_NUMBER: ans = ScalarReal(obj->floatval); if(xmlXPathIsInf(obj->floatval)) REAL(ans)[0] = xmlXPathIsInf(obj->floatval) < 0 ? R_NegInf : R_PosInf; else if(xmlXPathIsNaN(obj->floatval)) REAL(ans)[0] = NA_REAL; break; case XPATH_STRING: ans = mkString(XMLCHAR_TO_CHAR(obj->stringval)); //XXX encoding break; case XPATH_POINT: case XPATH_RANGE: case XPATH_LOCATIONSET: case XPATH_USERS: PROBLEM "currently unsupported xmlXPathObject type %d in convertXPathObjectToR. Please send mail to maintainer.", obj->type WARN default: ans = R_NilValue; } return(ans); } #include <libxml/xpathInternals.h> /* For xmlXPathRegisterNs() */ xmlNsPtr * R_namespaceArray(SEXP namespaces, xmlXPathContextPtr ctxt) { int i, n; SEXP names = GET_NAMES(namespaces); xmlNsPtr *els; n = GET_LENGTH(namespaces); els = xmlMallocAtomic(sizeof(xmlNsPtr) * n); if(!els) { PROBLEM "Failed to allocated space for namespaces" ERROR; } for(i = 0; i < n; i++) { /*XXX who owns these strings. */ const xmlChar *prefix, *href; href = CHAR_TO_XMLCHAR(strdup(CHAR_DEREF(STRING_ELT(namespaces, i)))); prefix = names == NULL_USER_OBJECT ? CHAR_TO_XMLCHAR("") /* NULL */ : CHAR_TO_XMLCHAR(strdup(CHAR_DEREF(STRING_ELT(names, i)))); els[i] = xmlNewNs(NULL, href, prefix); if(ctxt) xmlXPathRegisterNs(ctxt, prefix, href); } return(els); }
xmlXPathObjectPtr get_nodeset(xmlDocPtr doc, const xmlChar *xpath) { xmlXPathContextPtr context; xmlXPathObjectPtr result; context = xmlXPathNewContext(doc); if (context == NULL) { printf("context is NULL\n"); return NULL; } xmlXPathRegisterNs(context,(const xmlChar*)"w",(const xmlChar*)"http://schemas.openxmlformats.org/wordprocessingml/2006/main");// //默认ns : @"//*[local-name()='price'] " result = xmlXPathEvalExpression(xpath, context); xmlXPathFreeContext(context); if (result == NULL) { printf("xmlXPathEvalExpression return NULL\n"); return NULL; } if (xmlXPathNodeSetIsEmpty(result->nodesetval)) { xmlXPathFreeObject(result); printf("nodeset is empty\n"); return NULL; } return result; }
char * GetDataAndUpdateModel(xmlDoc *modelDocPtr, char *xpath, char *val, int op) { // op = 1 => update // op = 2 => read xmlXPathContextPtr xpathcontext; xmlXPathObjectPtr xpathobject; //TODO Error checking // Namespace issue's xmlNodeSetPtr nodes; xpathcontext = xmlXPathNewContext(modelDocPtr); if(xmlXPathRegisterNs( xpathcontext, (xmlChar*)"xf", (xmlChar*)"http://www.w3.org/2002/xforms")){ printf("Could not register %s=%s\n", "xf", "http://www.w3.org/2002/xforms"); return 0; } if(xpathcontext == NULL) { fprintf(stderr,"Error: unable to create new XPath context\n"); return 0; } xpathobject = xmlXPathEvalExpression((xmlChar *)xpath, xpathcontext); nodes = xpathobject->nodesetval; if( op == 1) { //update xmlNodeSetContent(nodes->nodeTab[0],(xmlChar *)val); return 0; } else if( op == 2 ) { //read return (char *)xmlNodeGetContent(nodes->nodeTab[0]); } return 0; }
static int xmlSecXPathDataRegisterNamespaces(xmlSecXPathDataPtr data, xmlNodePtr node) { xmlNodePtr cur; xmlNsPtr ns; int ret; xmlSecAssert2(data != NULL, -1); xmlSecAssert2(data->ctx != NULL, -1); xmlSecAssert2(node != NULL, -1); /* register namespaces */ for(cur = node; cur != NULL; cur = cur->parent) { for(ns = cur->nsDef; ns != NULL; ns = ns->next) { /* check that we have no other namespace with same prefix already */ if((ns->prefix != NULL) && (xmlXPathNsLookup(data->ctx, ns->prefix) == NULL)){ ret = xmlXPathRegisterNs(data->ctx, ns->prefix, ns->href); if(ret != 0) { xmlSecError(XMLSEC_ERRORS_HERE, NULL, "xmlXPathRegisterNs", XMLSEC_ERRORS_R_XML_FAILED, "href=%s;prefix=%s", xmlSecErrorsSafeString(ns->href), xmlSecErrorsSafeString(ns->prefix)); return(-1); } } } } return(0); }
static SeedValue seed_xml_xpath_register_ns (SeedContext ctx, SeedObject function, SeedObject this_object, gsize argument_count, const SeedValue arguments[], SeedException * exception) { xmlXPathContextPtr xpath; guchar *prefix; guchar *ns_uri; if (argument_count != 2) { seed_make_exception (ctx, exception, "ArgumentError", "xpathRegisterNs expects 2 arguments, got %zd", argument_count); return seed_make_undefined (ctx); } xpath = XML_XPATH_PRIV (this_object); prefix = (guchar *)seed_value_to_string (ctx, arguments[0], exception); ns_uri = (guchar *)seed_value_to_string (ctx, arguments[1], exception); xmlXPathRegisterNs (xpath, prefix, ns_uri); g_free (prefix); g_free (ns_uri); return seed_make_undefined (ctx); }
XMLNodeList XMLNode::XPathLookup(const std::string& xpathExpr, const NS& nsList) { std::list<XMLNode> retlist; if (node_ == NULL) return retlist; if (node_->type != XML_ELEMENT_NODE) return retlist; xmlDocPtr doc = node_->doc; if (doc == NULL) return retlist; xmlXPathContextPtr xpathCtx = xmlXPathNewContext(doc); for (NS::const_iterator ns = nsList.begin(); ns != nsList.end(); ++ns) xmlXPathRegisterNs(xpathCtx, (xmlChar*)ns->first.c_str(), (xmlChar*)ns->second.c_str()); xmlXPathObjectPtr xpathObj = xmlXPathEvalExpression((const xmlChar*)(xpathExpr.c_str()), xpathCtx); if (xpathObj && xpathObj->nodesetval && xpathObj->nodesetval->nodeNr) { xmlNodeSetPtr nodes = xpathObj->nodesetval; int size = nodes->nodeNr; for (int i = 0; i < size; ++i) if (nodes->nodeTab[i]->type == XML_ELEMENT_NODE) { xmlNodePtr cur = nodes->nodeTab[i]; xmlNodePtr parent = cur; for (; parent; parent = parent->parent) if (parent == node_) break; if (parent) retlist.push_back(XMLNode(cur)); } } xmlXPathFreeObject(xpathObj); xmlXPathFreeContext(xpathCtx); return retlist; }
/** * exsltStrXpathCtxtRegister: * * Registers the EXSLT - Strings module for use outside XSLT */ int exsltStrXpathCtxtRegister (xmlXPathContextPtr ctxt, const xmlChar *prefix) { if (ctxt && prefix && !xmlXPathRegisterNs(ctxt, prefix, (const xmlChar *) EXSLT_STRINGS_NAMESPACE) && !xmlXPathRegisterFuncNS(ctxt, (const xmlChar *) "encode-uri", (const xmlChar *) EXSLT_STRINGS_NAMESPACE, exsltStrEncodeUriFunction) && !xmlXPathRegisterFuncNS(ctxt, (const xmlChar *) "decode-uri", (const xmlChar *) EXSLT_STRINGS_NAMESPACE, exsltStrDecodeUriFunction) && !xmlXPathRegisterFuncNS(ctxt, (const xmlChar *) "padding", (const xmlChar *) EXSLT_STRINGS_NAMESPACE, exsltStrPaddingFunction) && !xmlXPathRegisterFuncNS(ctxt, (const xmlChar *) "align", (const xmlChar *) EXSLT_STRINGS_NAMESPACE, exsltStrAlignFunction) && !xmlXPathRegisterFuncNS(ctxt, (const xmlChar *) "concat", (const xmlChar *) EXSLT_STRINGS_NAMESPACE, exsltStrConcatFunction)) { return 0; } return -1; }
/** * @arg xpath XPath expression to evaluate * @doc document over which to evaluate * @arg pctxt can be NULL * @return list of matching nodes. The caller will have to free it using xmlXPathFreeNodeSet(). */ xmlNodeSetPtr find_node_set(const char *xpath, const xmlDocPtr doc, xmlXPathParserContextPtr *pctxt) { xmlXPathContextPtr ctxt = xmlXPathNewContext(doc); if(!ctxt) { g_printerr(G_STRLOC ": Failed to allocate XPathContext!\n"); return NULL; } if(xmlXPathRegisterNs(ctxt, (xmlChar *) FREEDICT_EDITOR_NAMESPACE_PREFIX, (xmlChar *) FREEDICT_EDITOR_NAMESPACE)) { g_printerr("Warning: Unable to register XSLT-Namespace prefix \"%s\"" " for URI \"%s\"\n", FREEDICT_EDITOR_NAMESPACE_PREFIX, FREEDICT_EDITOR_NAMESPACE); } if(xmlXPathRegisterFuncNS(ctxt, (xmlChar *) "unbalanced-braces", (xmlChar *) FREEDICT_EDITOR_NAMESPACE, freedict_xpath_extension_unbalanced_braces)) g_printerr("Warning: Unable to register XPath extension function " "\"unbalanced-braces\" for URI \"%s\"\n", FREEDICT_EDITOR_NAMESPACE); xmlXPathParserContextPtr pctxt2; if(!pctxt) pctxt = &pctxt2; xmlXPathObjectPtr xpobj = my_xmlXPathEvalExpression((xmlChar *) xpath, ctxt, pctxt); if(!xpobj) { g_printerr(G_STRLOC ": No XPathObject!\n"); xmlXPathFreeContext(ctxt); return NULL; } if(!(xpobj->nodesetval)) { g_printerr(G_STRLOC ": No nodeset!\n"); xmlXPathFreeObject(xpobj); xmlXPathFreeContext(ctxt); return NULL; } if(!(xpobj->nodesetval->nodeNr)) { //g_printerr("0 nodes!\n"); xmlXPathFreeObject(xpobj); xmlXPathFreeContext(ctxt); return NULL; } xmlXPathFreeContext(ctxt); xmlNodeSetPtr nodes = xmlMalloc(sizeof(xmlNodeSet)); // XXX copying is slow... memcpy(nodes, xpobj->nodesetval, sizeof(xmlNodeSet)); // I don't understand the naming of this function. According to the // documentation, it frees xpobj, but not its nodelist, if it // contained one. So it should be called xmlXPathFreeObjectButNotNodeSetList(). xmlXPathFreeNodeSetList(xpobj); return nodes; }
/** * register the namespace from @ns_arr to @ctxt */ static void nsarr_xpath_register(xmlXPathContextPtr ctxt) { int ns; for (ns = 0; ns_arr[ns]; ns += 2) { xmlXPathRegisterNs(ctxt, ns_arr[ns], ns_arr[ns+1]); } }
void XPathContext::unregister_namespace(const std::string& prefix) { if (0 != xmlXPathRegisterNs(m_cobj, reinterpret_cast<const xmlChar*>(prefix.c_str()), NULL)) { throw exception("xmlXPathRegisterNs returned -1"); } }
/** * xslDbgShellPrintList: * @ctxt: The current shell context * @arg: What xpath to display and in UTF-8 * @dir: If 1 print in dir mode?, * otherwise ls mode * * Print list of nodes in either ls or dir format * * Returns 1 on success, * 0 otherwise */ int xslDbgShellPrintList(xmlShellCtxtPtr ctxt, xmlChar * arg, int dir) { xmlXPathObjectPtr list; int result = 0; if (!ctxt || !arg) { #ifdef WITH_XSLDBG_DEBUG_PROCESS xsltGenericError(xsltGenericErrorContext, "Error: NULL arguments provided\n"); #endif return result; } if (arg[0] == 0) { if (dir) xmlShellDir(ctxt, NULL, ctxt->node, NULL); else xmlShellList(ctxt, NULL, ctxt->node, NULL); result = 1; /*assume that this worked */ } else { ctxt->pctxt->node = ctxt->node; ctxt->pctxt->node = ctxt->node; if (!xmlXPathNsLookup(ctxt->pctxt, (xmlChar *) "xsl")) xmlXPathRegisterNs(ctxt->pctxt, (xmlChar *) "xsl", XSLT_NAMESPACE); list = xmlXPathEval(arg, ctxt->pctxt); if (list != NULL) { switch (list->type) { case XPATH_NODESET:{ int indx; for (indx = 0; indx < list->nodesetval->nodeNr; indx++) { if (dir) xmlShellList(ctxt, NULL, list->nodesetval-> nodeTab[indx], NULL); else xmlShellList(ctxt, NULL, list->nodesetval-> nodeTab[indx], NULL); } result = 1; break; } default: xmlShellPrintXPathError(list->type, (char *) arg); } xmlXPathFreeObject(list); } else { xsldbgGenericErrorFunc(i18n("Error: XPath %1 results in an empty Node Set.\n").arg(xsldbgText(arg))); } ctxt->pctxt->node = NULL; } return result; }
static int ds_sds_compose_catalog_has_uri(xmlDocPtr doc, xmlNodePtr catalog, const char* uri) { xmlXPathContextPtr xpathCtx = xmlXPathNewContext(doc); if (xpathCtx == NULL) { oscap_seterr(OSCAP_EFAMILY_XML, "Error: unable to create a new XPath context."); return -1; } xmlXPathRegisterNs(xpathCtx, BAD_CAST "cat", BAD_CAST cat_ns_uri); xmlXPathRegisterNs(xpathCtx, BAD_CAST "xlink", BAD_CAST xlink_ns_uri); // limit xpath execution to just the catalog node // this is done for performance reasons xpathCtx->node = catalog; const char* expression = oscap_sprintf("cat:uri[@uri = '%s']", uri); xmlXPathObjectPtr xpathObj = xmlXPathEvalExpression( BAD_CAST expression, xpathCtx); oscap_free(expression); if (xpathObj == NULL) { oscap_seterr(OSCAP_EFAMILY_XML, "Error: Unable to evalute XPath expression."); xmlXPathFreeContext(xpathCtx); return -1; } int result = 0; xmlNodeSetPtr nodeset = xpathObj->nodesetval; if (nodeset != NULL) result = nodeset->nodeNr > 0 ? 0 : 1; xmlXPathFreeObject(xpathObj); xmlXPathFreeContext(xpathCtx); return result; }
void readDocument(Document* destination, char* filename) { DESTINATION = destination; // parse safeXmlInitParser(); DOCUMENT = xmlParseFile(filename); if (!DOCUMENT) { printf("Error reading %s\n", filename); return; } // validate if (!isValidSBOL(DOCUMENT)) { printf("%s is not a valid SBOL document.\n", filename); return; } // create XPath context CONTEXT = xmlXPathNewContext(DOCUMENT); xmlXPathRegisterNs(CONTEXT, (const xmlChar*)NSPREFIX_SBOL, (const xmlChar*)NSURL_SBOL); xmlXPathRegisterNs(CONTEXT, (const xmlChar*)NSPREFIX_RDF, (const xmlChar*)NSURL_RDF); #define GLOBAL_XPATH BAD_CAST "//" NSPREFIX_SBOL ":" // create all the SBOLObjects processNodes(readDNASequenceContent, GLOBAL_XPATH NODENAME_DNASEQUENCE); processNodes(readSequenceAnnotationContent, GLOBAL_XPATH NODENAME_SEQUENCEANNOTATION); processNodes(readDNAComponentContent, GLOBAL_XPATH NODENAME_DNACOMPONENT); processNodes(readCollectionContent, GLOBAL_XPATH NODENAME_COLLECTION); // link them together with pointers processNodes(readSequenceAnnotationReferences, GLOBAL_XPATH NODENAME_SEQUENCEANNOTATION); processNodes(readDNAComponentReferences, GLOBAL_XPATH NODENAME_DNACOMPONENT); processNodes(readCollectionReferences, GLOBAL_XPATH NODENAME_COLLECTION); #undef GLOBAL_XPATH // clean up xmlXPathFreeContext(CONTEXT); xmlFreeDoc(DOCUMENT); DESTINATION = NULL; xmlCleanupParser(); }
static int ds_sds_compose_has_component_ref(xmlDocPtr doc, xmlNodePtr datastream, const char* filepath, const char* cref_id) { xmlXPathContextPtr xpathCtx = xmlXPathNewContext(doc); if (xpathCtx == NULL) { oscap_seterr(OSCAP_EFAMILY_XML, "Error: unable to create new XPath context."); return -1; } xmlXPathRegisterNs(xpathCtx, BAD_CAST "ds", BAD_CAST datastream_ns_uri); xmlXPathRegisterNs(xpathCtx, BAD_CAST "xlink", BAD_CAST xlink_ns_uri); // limit xpath execution to just the datastream node // this is done for performance reasons xpathCtx->node = datastream; const char* expression = oscap_sprintf("*/ds:component-ref[@xlink:href = '#%s' and @id = '%s']", filepath, cref_id); xmlXPathObjectPtr xpathObj = xmlXPathEvalExpression( BAD_CAST expression, xpathCtx); oscap_free(expression); if (xpathObj == NULL) { oscap_seterr(OSCAP_EFAMILY_XML, "Error: Unable to evalute XPath expression."); xmlXPathFreeContext(xpathCtx); return -1; } int result = 1; xmlNodeSetPtr nodeset = xpathObj->nodesetval; if (nodeset != NULL) result = nodeset->nodeNr > 0 ? 0 : 1; xmlXPathFreeObject(xpathObj); xmlXPathFreeContext(xpathCtx); return result; }
/** * register extra xml name spaces */ void xcaps_xpath_register_ns(xmlXPathContextPtr xpathCtx) { param_t *ns; ns = _xcaps_xpath_ns_root; while(ns) { xmlXPathRegisterNs(xpathCtx, (xmlChar*)ns->name.s, (xmlChar*)ns->body.s); ns = ns->next; } }
/* * call-seq: * register_ns(prefix, uri) * * Register the namespace with +prefix+ and +uri+. */ static VALUE register_ns(VALUE self, VALUE prefix, VALUE uri) { xmlXPathContextPtr ctx; Data_Get_Struct(self, xmlXPathContext, ctx); xmlXPathRegisterNs( ctx, (const xmlChar *)StringValuePtr(prefix), (const xmlChar *)StringValuePtr(uri) ); return self; }
int xslDbgShellCat(xsltTransformContextPtr styleCtxt, xmlShellCtxtPtr ctxt, xmlChar * arg) { xmlXPathObjectPtr list; int result = 0; static const char * QUIET_STR = "-q"; bool silenceCtxtErrors = false; if ((arg == NULL) || (xmlStrLen(arg) == 0)) arg = (xmlChar *) "."; /* Do we quietly ingore style context errors */ if (strncasecmp((char*)arg, QUIET_STR, strlen(QUIET_STR))== 0){ silenceCtxtErrors = true; arg = arg + strlen(QUIET_STR); while (isspace(*arg)){ arg++; } } if (!styleCtxt || !ctxt || !ctxt->node) { if (!(!xsldbgReachedFirstTemplate && silenceCtxtErrors)) xsldbgGenericErrorFunc(i18n("Warning: Unable to print expression. No stylesheet was properly loaded.\n")); return 0; } if ((arg == NULL) || (xmlStrLen(arg) == 0)) arg = (xmlChar *) "."; ctxt->pctxt->node = ctxt->node; if (!styleCtxt) { list = xmlXPathEval((xmlChar *) arg, ctxt->pctxt); } else { xmlNodePtr savenode = styleCtxt->xpathCtxt->node; ctxt->pctxt->node = ctxt->node; styleCtxt->xpathCtxt->node = ctxt->node; if (!xmlXPathNsLookup(styleCtxt->xpathCtxt, (xmlChar *) "xsl")) xmlXPathRegisterNs(styleCtxt->xpathCtxt, (xmlChar *) "xsl", XSLT_NAMESPACE); list = xmlXPathEval((xmlChar *) arg, styleCtxt->xpathCtxt); styleCtxt->xpathCtxt->node = savenode; } if (list != NULL) { result = printXPathObject(list, arg); xmlXPathFreeObject(list); } else { xsldbgGenericErrorFunc(i18n("Error: XPath %1 results in an empty Node Set.\n").arg(xsldbgText(arg))); } ctxt->pctxt->node = NULL; return result; }
/** * register top-level namespace definitions from @doc to @ctxt */ static void extract_ns_defs(xmlDocPtr doc, xmlXPathContextPtr ctxt) { xmlNsPtr nsDef; xmlNodePtr root = xmlDocGetRootElement(doc); if (!root) return; for (nsDef = root->nsDef; nsDef; nsDef = nsDef->next) { if (nsDef->prefix != NULL) /* can only register ns with prefix */ xmlXPathRegisterNs(ctxt, nsDef->prefix, nsDef->href); } }
void XPathContext::addNamespaceBinding(string prefix,string nsuri) { if(xmlXPathRegisterNs(this->xpathCtx,(const xmlChar*) prefix.c_str(), (const xmlChar*)nsuri.c_str()) != 0) { stringstream ss; ss << "Registering namespace "<<prefix<<":{"<<nsuri<<"} failed"; throw invalid_argument(ss.str()); } }
static void register_one_ns( HashStringValue::key_type key, HashStringValue::value_type value, Register_one_ns_info* info) { if(const String* svalue=value->get_string()) xmlXPathRegisterNs(info->ctxt, info->r->transcode(key), info->r->transcode(*svalue)); else throw Exception(PARSER_RUNTIME, new String(key, String::L_TAINTED), "value is %s, must be string or number", value->type()); }
int parse_tag_index(const char * document, Array * a, time_t * updated) { int rc = TAG_INDEX_OK; if (document && a) { xmlDocPtr doc = xmlReadMemory(document, strlen(document), "", NULL, XML_PARSE_COMPACT); if (doc) { xmlXPathContextPtr ctx = xmlXPathNewContext(doc); xmlXPathRegisterNs(ctx, BAD_CAST "atom", BAD_CAST ATOM); xmlXPathRegisterNs(ctx, BAD_CAST "classifier", BAD_CAST CLASSIFIER); if (updated) { *updated = get_element_value_time(ctx, "/atom:feed/atom:updated/text()"); } xmlXPathObjectPtr xp = xmlXPathEvalExpression(BAD_CAST "/atom:feed/atom:entry/atom:link[@rel = 'http://peerworks.org/classifier/training']", ctx); if (!xmlXPathNodeSetIsEmpty(xp->nodesetval)) { int i; for (i = 0; i < xp->nodesetval->nodeNr; i++) { xmlNodePtr node = xp->nodesetval->nodeTab[i]; char *url = xmlGetProp(node, BAD_CAST "href"); arr_add(a, url); } xmlXPathFreeObject(xp); xmlXPathFreeContext(ctx); xmlFreeDoc(doc); } else { info("No tags in tag index"); } } else { error("Could not parse tag index: %s", document); rc = TAG_INDEX_FAIL; } } return rc; }
value v2v_xml_xpathctx_ptr_register_ns (value xpathctxv, value prefix, value uri) { CAMLparam3 (xpathctxv, prefix, uri); xmlXPathContextPtr xpathctx; int r; xpathctx = Xpathctx_ptr_val (xpathctxv); r = xmlXPathRegisterNs (xpathctx, BAD_CAST String_val (prefix), BAD_CAST String_val (uri)); if (r == -1) caml_invalid_argument ("xpath_register_ns: unable to register namespace"); CAMLreturn (Val_unit); }