本文整理汇总了C++中xmlXPathNewContext函数的典型用法代码示例。如果您正苦于以下问题:C++ xmlXPathNewContext函数的具体用法?C++ xmlXPathNewContext怎么用?C++ xmlXPathNewContext使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了xmlXPathNewContext函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: subdesc_create_hashtable
/*****************************************************************************
函 数 名 : subdesc_create_hashtable
功能描述 : 根据doc中包括的有name的元素的数量创建hash表
输入参数 : doc sub文档 root 结构指针
输出参数 : 无
返 回 值 : ERR_SUCCESS成功 其他失败
调用函数 :
被调函数 :
============================================================================
修改历史 :
1.日 期 : 2008年8月26日
修改内容 : 新生成函数
*****************************************************************************/
static int subdesc_create_hashtable(xmlDocPtr doc, SUB_ROOT * root)
{
xmlXPathContextPtr xpathCtx;
int ret = ERROR_SUCCESS;
/* Create xpath evaluation context */
xpathCtx = xmlXPathNewContext(doc);
if(xpathCtx == NULL)
{
return ERROR_SYSTEM;
}
xmlXPathObjectPtr xpathObj;
/* Evaluate xpath expression */
xpathObj = xmlXPathEvalExpression((unsigned char*)"//*[@name]", xpathCtx);
if(xpathObj != NULL)
{
if(NULL == xpathObj->nodesetval ||
xpathObj->nodesetval->nodeNr ==0 ||
0 == hcreate_r(xpathObj->nodesetval->nodeNr,
(struct hsearch_data *)(root->_hashtable)))
{
ret = ERROR_SYSTEM;
}
xmlXPathFreeObject(xpathObj);
}
else
{
ret = ERROR_SYSTEM;
}
xmlXPathFreeContext(xpathCtx);
return ret;
}
示例2: xmlSecXPathDataCreate
static xmlSecXPathDataPtr
xmlSecXPathDataCreate(xmlSecXPathDataType type) {
xmlSecXPathDataPtr data;
data = (xmlSecXPathDataPtr) xmlMalloc(sizeof(xmlSecXPathData));
if(data == NULL) {
xmlSecMallocError(sizeof(xmlSecXPathData), NULL);
return(NULL);
}
memset(data, 0, sizeof(xmlSecXPathData));
data->type = type;
data->nodeSetType = xmlSecNodeSetTree;
/* create xpath or xpointer context */
switch(data->type) {
case xmlSecXPathDataTypeXPath:
case xmlSecXPathDataTypeXPath2:
data->ctx = xmlXPathNewContext(NULL); /* we'll set doc in the context later */
if(data->ctx == NULL) {
xmlSecXmlError("xmlXPathNewContext", NULL);
xmlSecXPathDataDestroy(data);
return(NULL);
}
break;
case xmlSecXPathDataTypeXPointer:
data->ctx = xmlXPtrNewContext(NULL, NULL, NULL); /* we'll set doc in the context later */
if(data->ctx == NULL) {
xmlSecXmlError("xmlXPtrNewContext", NULL);
xmlSecXPathDataDestroy(data);
return(NULL);
}
break;
}
return(data);
}
示例3: get_java_home
xmlChar* get_java_home(char *current_path)
{
char path_to_bbwp_properties[PATH_MAX+1];
strncpy(path_to_bbwp_properties, current_path, PATH_MAX+1);
strncat(path_to_bbwp_properties, "/bin/bbwp.properties", PATH_MAX+1);
xmlDocPtr doc = xmlParseFile(path_to_bbwp_properties);
if (doc == NULL) {
printf("error: could not parse file %s\n", path_to_bbwp_properties);
}
xmlXPathContextPtr context = xmlXPathNewContext(doc);
xmlChar * xpath = "/wcp/java";
xmlNodeSetPtr nodeset;
xmlXPathObjectPtr result = xmlXPathEvalExpression(xpath, context);
xmlChar *java_home;
if(xmlXPathNodeSetIsEmpty(result->nodesetval)){
printf("No result\n");
} else {
nodeset = result->nodesetval;
java_home = xmlNodeListGetString(doc, nodeset->nodeTab[0]->xmlChildrenNode, 1);
}
xmlFreeDoc(doc);
xmlXPathFreeContext(context);
xmlXPathFreeObject(result);
/*
* Free the global variables that may
* have been allocated by the parser.
*/
xmlCleanupParser();
return java_home;
}
示例4: parallelsDiskDescParseNode
static int parallelsDiskDescParseNode(xmlDocPtr xml,
xmlNodePtr root,
virStorageVolDefPtr def)
{
xmlXPathContextPtr ctxt = NULL;
int ret = -1;
if (STRNEQ((const char *)root->name, "Parallels_disk_image")) {
virReportError(VIR_ERR_XML_ERROR,
"%s", _("unknown root element for storage pool"));
goto cleanup;
}
ctxt = xmlXPathNewContext(xml);
if (ctxt == NULL) {
virReportOOMError();
goto cleanup;
}
ctxt->node = root;
if (virXPathULongLong("string(./Disk_Parameters/Disk_size)",
ctxt, &def->target.capacity) < 0) {
virReportError(VIR_ERR_XML_ERROR,
"%s", _("failed to get disk size from "
"the disk descriptor xml"));
goto cleanup;
}
def->target.capacity <<= 9;
def->target.allocation = def->target.capacity;
ret = 0;
cleanup:
xmlXPathFreeContext(ctxt);
return ret;
}
示例5: RS_XML_xpathNodeEval
SEXP
RS_XML_xpathNodeEval(SEXP s_node, SEXP path, SEXP namespaces, SEXP fun)
{
xmlXPathContextPtr ctxt = NULL;
xmlXPathObjectPtr result;
SEXP ans = NULL_USER_OBJECT;
xmlDocPtr doc;
if(TYPEOF(s_node) != EXTPTRSXP || R_ExternalPtrTag(s_node) != Rf_install("XMLInternalNode")) {
PROBLEM "xpathEval must be given an internal XML document object, 'XMLInternalNode'"
ERROR;
}
ctxt = xmlXPathNewContext(doc);
if(GET_LENGTH(namespaces)) {
ctxt->namespaces = R_namespaceArray(namespaces, ctxt); /* xmlCopyNamespaceList(doc); */
ctxt->nsNr = GET_LENGTH(namespaces);
}
result = xmlXPathEvalExpression(CHAR_TO_XMLCHAR(CHAR_DEREF(STRING_ELT(path, 0))), ctxt);
if(result)
ans = convertXPathObjectToR(result, fun);
xmlXPathFreeObject(result);
xmlXPathFreeContext(ctxt);
if(!result) {
PROBLEM "error evaluating xpath expression %s", CHAR_DEREF(STRING_ELT(path, 0))
ERROR;
}
return(ans);
}
示例6: new_child_node
void new_child_node (const char* filename, const xmlChar* xpathExpr,
const xmlChar *name, const xmlChar *content)
{
xmlDocPtr doc;
xmlXPathContextPtr xpathCtx;
xmlXPathObjectPtr xpathObj;
xmlKeepBlanksDefault(0);
/* Load XML document */
doc = xmlParseFile(filename);
if (doc == NULL) {
fprintf(stderr, "Error: unable to parse file \"%s\"\n", filename);
return;
}
/* Create xpath evaluation context */
xpathCtx = xmlXPathNewContext(doc);
if(xpathCtx == NULL) {
fprintf(stderr,"Error: unable to create new XPath context\n");
xmlFreeDoc(doc);
return;
}
/* Evaluate xpath expression */
xpathObj = xmlXPathEvalExpression(xpathExpr, xpathCtx);
if(xpathObj == NULL) {
fprintf(stderr,"Error: unable to evaluate xpath expression \"%s\"\n", xpathExpr);
xmlXPathFreeContext(xpathCtx);
xmlFreeDoc(doc);
return;
}
xmlNewTextChild (xpathObj->nodesetval->nodeTab[0], NULL, name, content);
xmlXPathFreeObject(xpathObj);
xmlXPathFreeContext(xpathCtx);
xmlSaveFormatFile (filename, doc, 1);
xmlFreeDoc(doc);
}
示例7: flickcurl_auth_checkToken
/**
* flickcurl_auth_checkToken:
* @fc: flickcurl context
* @token: token string
*
* Get the credentials attached to an authentication token.
*
* Implements flickr.auth.checkToken (0.9)
* Must be signed.
*
* FIXME: Cannot confirm this works, get intermittent results.
*
* Return value: permissions string or NULL on failure
**/
char*
flickcurl_auth_checkToken(flickcurl* fc, const char* token)
{
const char * parameters[6][2];
int count = 0;
char *perms = NULL;
xmlDocPtr doc = NULL;
xmlXPathContextPtr xpathCtx = NULL;
if(!token)
return NULL;
parameters[count][0] = "auth_token";
parameters[count++][1] = (char*)token;
parameters[count][0] = NULL;
flickcurl_set_sign(fc);
if(flickcurl_prepare(fc, "flickr.auth.checkToken", parameters, count))
goto tidy;
doc = flickcurl_invoke(fc);
if(!doc)
goto tidy;
xpathCtx = xmlXPathNewContext(doc);
if(xpathCtx) {
perms = flickcurl_xpath_eval(fc, xpathCtx,
(const xmlChar*)"/rsp/auth/perms");
xmlXPathFreeContext(xpathCtx);
}
tidy:
return perms;
}
示例8: flickcurl_people_getUploadStatus
/**
* flickcurl_people_getUploadStatus:
* @fc: flickcurl context
*
* Returns information for the calling user related to photo uploads.
*
* Implements flickr.people.getUploadStatus (0.13)
*
* Return value: non-0 on failure
**/
flickcurl_user_upload_status*
flickcurl_people_getUploadStatus(flickcurl* fc)
{
const char* parameters[7][2];
int count=0;
xmlDocPtr doc=NULL;
xmlXPathContextPtr xpathCtx=NULL;
flickcurl_user_upload_status* status=NULL;
parameters[count][0] = NULL;
if(flickcurl_prepare(fc, "flickr.people.getUploadStatus", parameters, count))
goto tidy;
doc=flickcurl_invoke(fc);
if(!doc)
goto tidy;
xpathCtx = xmlXPathNewContext(doc);
if(!xpathCtx) {
flickcurl_error(fc, "Failed to create XPath context for document");
fc->failed=1;
goto tidy;
}
status=flickcurl_build_user_upload_status(fc, xpathCtx, (const xmlChar*)"/rsp/user/*");
tidy:
if(xpathCtx)
xmlXPathFreeContext(xpathCtx);
if(fc->failed)
status=NULL;
return status;
}
示例9: flickcurl_people_getInfo
/**
* flickcurl_people_getInfo:
* @fc: flickcurl context
* @user_id: user NSID
*
* Get information about a person
*
* Implements flickr.people.getInfo (0.6)
*
* NSID can be found by flickcurl_people_findByEmail() or
* flickcurl_people_findByUsername().
*
* Return value: #flickcurl_person object or NULL on failure
**/
flickcurl_person*
flickcurl_people_getInfo(flickcurl* fc, const char* user_id)
{
xmlDocPtr doc = NULL;
xmlXPathContextPtr xpathCtx = NULL;
flickcurl_person* person = NULL;
flickcurl_init_params(fc, 0);
flickcurl_add_param(fc, "user_id", user_id);
flickcurl_end_params(fc);
if(flickcurl_prepare(fc, "flickr.people.getInfo"))
goto tidy;
doc = flickcurl_invoke(fc);
if(!doc)
goto tidy;
xpathCtx = xmlXPathNewContext(doc);
if(!xpathCtx) {
flickcurl_error(fc, "Failed to create XPath context for document");
fc->failed = 1;
goto tidy;
}
person = flickcurl_build_person(fc, xpathCtx, (const xmlChar*)"/rsp/person");
tidy:
if(xpathCtx)
xmlXPathFreeContext(xpathCtx);
if(fc->failed)
person = NULL;
return person;
}
示例10: xmlXPathNewContext
std::string OSConfigure::readonestring ( std::string path )
{
xmlChar * xpath = ( xmlChar * ) path.c_str ();
xmlChar *keyword;
std::string retstring;
xmlNodeSetPtr nodeset;
xmlXPathContextPtr context;
xmlXPathObjectPtr result;
context = xmlXPathNewContext ( doc );
if ( context == NULL )
return "";
result = xmlXPathEvalExpression ( xpath, context );
xmlXPathFreeContext ( context );
if ( result == NULL )
return "";
if ( xmlXPathNodeSetIsEmpty ( result->nodesetval ) )
{
return "";
}
nodeset = result->nodesetval;
keyword = xmlNodeListGetString ( doc, nodeset->nodeTab[ 0 ] ->xmlChildrenNode, 1 );
if ( keyword != NULL )
retstring = std::string ( ( char * ) keyword );
xmlFree ( keyword );
xmlXPathFreeObject ( result );
return retstring;
}
示例11: lock
// Evaluate an XPath expression and return matching Nodes.
NodeList Document::findXPath(const std::string& path) const
{
std::lock_guard<std::mutex> lock(_lock);
// Set up the XPath context
xmlXPathContextPtr context = xmlXPathNewContext(_xmlDoc);
if (context == NULL) {
rConsoleError() << "ERROR: xml::findPath() failed to create XPath context "
<< "when searching for " << path << std::endl;
throw XPathException("Failed to create XPath context");
}
// Evaluate the expression
const xmlChar* xpath = reinterpret_cast<const xmlChar*>(path.c_str());
xmlXPathObjectPtr result = xmlXPathEvalExpression(xpath, context);
xmlXPathFreeContext(context);
if (result == NULL) {
rConsoleError() << "ERROR: xml::findPath() failed to evaluate expression "
<< path << std::endl;
throw XPathException("Failed to evaluate XPath expression");
}
// Construct the return vector. This may be empty if the provided XPath
// expression does not identify any nodes.
NodeList retval;
xmlNodeSetPtr nodeset = result->nodesetval;
if (nodeset != NULL) {
for (int i = 0; i < nodeset->nodeNr; i++) {
retval.push_back(Node(nodeset->nodeTab[i]));
}
}
xmlXPathFreeObject(result);
return retval;
}
示例12: get_nodes_with_name_xpath
xmlXPathObjectPtr get_nodes_with_name_xpath( XMLDoc *tree, FeriteString *str )
{
char *xpath, *x = "descendant-or-self::node()";
xmlXPathCompExprPtr comp = NULL;
int length = strlen( x ) + str->length + 4;
xpath = malloc(length);
memset(xpath, '\0', length );
sprintf( xpath, "%s/%s", x, str->data );
comp = xmlXPathCompile( BAD_CAST xpath );
free(xpath);
if( comp != NULL ) {
xmlXPathObjectPtr res = NULL;
xmlXPathContextPtr ctxt = xmlXPathNewContext( tree->doc );
ctxt->node = tree->node;
res = xmlXPathCompiledEval( comp, ctxt );
xmlXPathFreeContext( ctxt );
xmlXPathFreeCompExpr( comp );
return res;
}
return NULL;
}
示例13: process_recursive
int process_recursive(xmlDocPtr doc, char *xpath, int level, char *fn)
{
int i, num;
xmlXPathContextPtr context;
xmlXPathObjectPtr op;
xmlNodeSetPtr nodeset;
context = xmlXPathNewContext(doc);
if (context == NULL) {
DPRINTF("Error in xmlXPathNewContext\n");
return 0;
}
DPRINTF("Trying to access xPath node %s\n", xpath);
op = xmlXPathEvalExpression( (xmlChar *)xpath, context);
xmlXPathFreeContext(context);
if (op == NULL) {
DPRINTF("Error in xmlXPathEvalExpression\n");
return -EIO;
}
if(xmlXPathNodeSetIsEmpty(op->nodesetval)) {
xmlXPathFreeObject(op);
DPRINTF("No result\n");
return -EINVAL;
}
nodeset = op->nodesetval;
num = nodeset->nodeNr;
for (i = 0; i < num; i++)
process_data(doc, nodeset->nodeTab[i], xpath, level, fn);
xmlXPathFreeObject(op);
return 0;
}
示例14: getnodeset
xmlXPathObjectPtr
getnodeset (xmlDocPtr doc, xmlChar *xpath) {
xmlXPathContextPtr context;
xmlXPathObjectPtr result;
context = xmlXPathNewContext(doc);
if (context == NULL) {
printf("[ getnodeset ] : [ ERROR ] : xmlXPathNewContext\n");
return NULL;
}
result = xmlXPathEvalExpression(xpath, context);
xmlXPathFreeContext(context);
if (result == NULL) {
printf("[ getnodeset ] : [ ERROR ] : xmlXPathEvalExpression\n");
return NULL;
}
if(xmlXPathNodeSetIsEmpty(result->nodesetval)){
xmlXPathFreeObject(result);
if(DEBUG>2) printf("[ getnodeset ] : [ WARNING ] : no xmlXPath result found\n");
return NULL;
}
return result;
}
示例15: parse_ref_tag
static struct ldap_object_node *
parse_ref_tag(xmlNodePtr curr_node,
struct ldap_object_node **objs,
struct ldap_attr_node **attrs,
struct idinfo *ids)
{
xmlXPathObjectPtr xobj;
xmlXPathContextPtr xctx;
char query[1024];
char *n;
dbg_printf("Trying to parse ref tag\n");
n = (char *)xmlGetProp(curr_node, (xmlChar *)"name");
snprintf(query, sizeof(query), "//define[@name=\"%s\"]", n);
xctx = xmlXPathNewContext(curr_node->doc);
assert(xctx);
xobj = xmlXPathEvalExpression((xmlChar *)query, xctx);
printf("%d nodes match %s\n", xobj->nodesetval->nodeNr, query);
assert(0);
return NULL;
}