本文整理汇总了C++中xmlXPathFreeContext函数的典型用法代码示例。如果您正苦于以下问题:C++ xmlXPathFreeContext函数的具体用法?C++ xmlXPathFreeContext怎么用?C++ xmlXPathFreeContext使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了xmlXPathFreeContext函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parserDocByKey
/***********************************************
* 得到记录的总数及记录集 *
* 成功返回记录数及记录集 *
* 失败则返回0和NULL *
* resultset用完后请手动free *
***********************************************/
xmlXPathObjectPtr parserDocByKey(xmlDocPtr doc, byte * keyName, int * num)
{
*num = 0;
xmlXPathContextPtr context;
xmlXPathObjectPtr result;
xmlNodeSetPtr nodeset;
xmlInitParser();
context = xmlXPathNewContext(doc);
if(context == NULL) {
//xmlFreeDoc(doc);
ErrorLog(ERROR, "open doc fail, doc content is empty");
printf("open doc fail, doc content is empty");
return NULL;
}
result = xmlXPathEvalExpression((const xmlChar *)keyName, context);
xmlXPathFreeContext(context);
if(result == NULL) {
//xmlFreeDoc(doc);
ErrorLog(ERROR, "xmlPathEvalExpression return NULL");
printf("xmlPathEvalExpression return NULL");
return NULL;
}
//print_xpath_nodes(result->nodesetval, stdout);
nodeset = result->nodesetval;
if(nodeset == NULL) {
xmlXPathFreeObject(result);
ErrorLog(ERROR, "nodeset is null");
printf("nodeset is null");
return NULL;
}
if(xmlXPathNodeSetIsEmpty(result->nodesetval)) {
xmlXPathFreeObject(result);
ErrorLog(ERROR, "nodeset is empty");
printf("nodeset is empty");
return NULL;
}
*num = nodeset->nodeNr;
//xmlXPathFreeObject (result);
xmlCleanupParser();
return result;
}
示例2: string
xmlXPathObjectPtr TrackerConfig::findConfigNodes(const string& sXPathExpr) const
{
string sFullPath = string("/trackerconfig"+sXPathExpr);
xmlXPathContextPtr xpCtx;
xmlXPathObjectPtr xpElement;
xpCtx = xmlXPathNewContext(m_Doc);
if(!xpCtx) {
AVG_LOG_ERROR("Unable to create new XPath context");
return NULL;
}
xpElement = xmlXPathEvalExpression(BAD_CAST sFullPath.c_str(), xpCtx);
if(!xpElement) {
AVG_LOG_ERROR("Unable to evaluate XPath expression '"
<< sFullPath << "'");
xmlXPathFreeContext(xpCtx);
return NULL;
}
xmlXPathFreeContext(xpCtx);
return xpElement;
}
示例3: cx_parse_xml
static int cx_parse_xml(cx_t *db, char *xml) /* {{{ */
{
/* Load the XML */
xmlDocPtr doc = xmlParseDoc(BAD_CAST xml);
if (doc == NULL) {
ERROR("curl_xml plugin: Failed to parse the xml document - %s", xml);
return -1;
}
xmlXPathContextPtr xpath_ctx = xmlXPathNewContext(doc);
if (xpath_ctx == NULL) {
ERROR("curl_xml plugin: Failed to create the xml context");
xmlFreeDoc(doc);
return -1;
}
for (size_t i = 0; i < db->namespaces_num; i++) {
cx_namespace_t const *ns = db->namespaces + i;
int status =
xmlXPathRegisterNs(xpath_ctx, BAD_CAST ns->prefix, BAD_CAST ns->url);
if (status != 0) {
ERROR("curl_xml plugin: "
"unable to register NS with prefix=\"%s\" and href=\"%s\"\n",
ns->prefix, ns->url);
xmlXPathFreeContext(xpath_ctx);
xmlFreeDoc(doc);
return status;
}
}
int status = cx_handle_parsed_xml(db, doc, xpath_ctx);
/* Cleanup */
xmlXPathFreeContext(xpath_ctx);
xmlFreeDoc(doc);
return status;
} /* }}} cx_parse_xml */
示例4: parse_rss_item
bool parse_rss_item(xmlNodePtr node, wxString &url, wxString &version, wxString &md5, wxDateTime &datetime) {
xmlXPathContextPtr xp_ctx = xmlXPathNewContext(node->doc);
xp_ctx->node = node;
int ret;
ret = xmlXPathRegisterNs(xp_ctx,
BAD_CAST "media",
BAD_CAST "http://video.search.yahoo.com/mrss/");
assert(ret == 0);
wxString datetime_string;
wxString* str_array[] = { &md5, &url, &datetime_string };
const char * xpath_array[] = { "./media:content/media:hash[@algo='md5']", "./link", "./pubDate" };
for (size_t i = 0; i < sizeof(str_array) / sizeof(str_array[0]); i++) {
xmlNodePtr _node = uxmlXPathGetNode(BAD_CAST xpath_array[i], xp_ctx);
if (_node == NULL || _node->xmlChildrenNode == NULL) {
xmlXPathFreeContext(xp_ctx);
return false;
}
xmlChar* _str = xmlNodeListGetString(_node->doc, _node->xmlChildrenNode, 1);
*str_array[i] = SC::U2S(_str);
xmlFree(_str);
}
if (datetime.ParseRfc822Date(datetime_string.c_str()) == NULL) {
xmlXPathFreeContext(xp_ctx);
return false;
}
version = url2version(url);
return true;
}
示例5: xmlSchematronFreeParserCtxt
/**
* xmlSchematronFreeParserCtxt:
* @ctxt: the schema parser context
*
* Free the resources associated to the schema parser context
*/
void
xmlSchematronFreeParserCtxt(xmlSchematronParserCtxtPtr ctxt)
{
if (ctxt == NULL)
return;
if (ctxt->doc != NULL && !ctxt->preserve)
xmlFreeDoc(ctxt->doc);
if (ctxt->xctxt != NULL) {
xmlXPathFreeContext(ctxt->xctxt);
}
if (ctxt->namespaces != NULL)
xmlFree((char **) ctxt->namespaces);
xmlDictFree(ctxt->dict);
xmlFree(ctxt);
}
示例6: xmlXPathNewContext
void XaLibDom::AddValueElementByXPath(xmlDocPtr XmlDomDoc, string XPathExpr, string ValueValue){
xmlNodePtr cur;
xmlNodePtr OptionsNode;
xpathCtx = xmlXPathNewContext(XmlDomDoc);
xpathObj = xmlXPathEvalExpression((const xmlChar *)XPathExpr.c_str(), xpathCtx);
cur = xpathObj->nodesetval->nodeTab[0];
OptionsNode = xmlNewChild(cur, NULL, (const xmlChar *) "value", (const xmlChar *)ValueValue.c_str());
xmlXPathFreeObject(xpathObj);
xmlXPathFreeContext(xpathCtx);
};
示例7: getnodeset
xmlXPathObjectPtr getnodeset(xmlDocPtr doc, xmlChar *xpath)
{
xmlXPathContextPtr context;
xmlXPathObjectPtr result;
context = xmlXPathNewContext(doc);
result = xmlXPathEvalExpression(xpath, context);
if (xmlXPathNodeSetIsEmpty(result->nodesetval)) {
printf("No result\n");
return NULL;
}
xmlXPathFreeContext(context);
return result;
}
示例8: flickcurl_collections_getTree
/**
* flickcurl_collections_getTree:
* @fc: flickcurl context
* @collection_id: The ID of the collection to fetch a tree for, or zero to fetch the root collection. Defaults to zero. (or NULL)
* @user_id: The ID of the account to fetch the collection tree for. Deafults to the calling user. (or NULL)
*
* Returns a tree (or sub tree) of collections belonging to a given user.
*
* Implements flickr.collections.getTree (1.12)
*
* Return value: a collection or NULL on failure
**/
flickcurl_collection*
flickcurl_collections_getTree(flickcurl* fc, const char* collection_id,
const char* user_id)
{
const char* parameters[9][2];
int count = 0;
xmlDocPtr doc = NULL;
xmlXPathContextPtr xpathCtx = NULL;
flickcurl_collection* collection = NULL;
if(collection_id) {
parameters[count][0] = "collection_id";
parameters[count++][1]= collection_id;
}
if(user_id) {
parameters[count][0] = "user_id";
parameters[count++][1]= user_id;
}
parameters[count][0] = NULL;
if(flickcurl_prepare(fc, "flickr.collections.getTree", 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;
}
collection = flickcurl_build_collection(fc, xpathCtx,
(const xmlChar*)"/rsp/collections/collection");
tidy:
if(xpathCtx)
xmlXPathFreeContext(xpathCtx);
if(fc->failed)
collection = NULL;
return collection;
}
示例9: cpuTestLoadMultiXML
static virCPUDefPtr *
cpuTestLoadMultiXML(const char *arch,
const char *name,
unsigned int *count)
{
char *xml = NULL;
xmlDocPtr doc = NULL;
xmlXPathContextPtr ctxt = NULL;
xmlNodePtr *nodes = NULL;
virCPUDefPtr *cpus = NULL;
int n;
int i;
if (virAsprintf(&xml, "%s/cputestdata/%s-%s.xml", abs_srcdir, arch, name) < 0)
goto cleanup;
if (!(doc = virXMLParseFileCtxt(xml, &ctxt)))
goto error;
n = virXPathNodeSet("/cpuTest/cpu", ctxt, &nodes);
if (n <= 0 || !(cpus = calloc(n, sizeof(virCPUDefPtr))))
goto error;
for (i = 0; i < n; i++) {
ctxt->node = nodes[i];
cpus[i] = virCPUDefParseXML(nodes[i], ctxt, VIR_CPU_TYPE_HOST);
if (!cpus[i])
goto error;
}
*count = n;
cleanup:
free(xml);
free(nodes);
xmlXPathFreeContext(ctxt);
xmlFreeDoc(doc);
return cpus;
error:
if (cpus) {
for (i = 0; i < n; i++)
virCPUDefFree(cpus[i]);
free(cpus);
cpus = NULL;
}
goto cleanup;
}
示例10: flickcurl_photos_geo_correctLocation
/**
* flickcurl_photos_geo_correctLocation:
* @fc: flickcurl context
* @photo_id: The ID of the photo whose WOE location is being corrected.
* @place_id: A Flickr Places ID (or NULL)
* @woe_id: A Where On Earth (WOE) ID (or NULL)
*
* Correct a photo location.
*
* You must pass either a valid Places ID in @place_id or a WOE ID in @woe_id.
*
* Implements flickr.photos.geo.correctLocation (1.8)
*
* Return value: non-0 on failure
**/
int
flickcurl_photos_geo_correctLocation(flickcurl* fc, const char* photo_id,
const char* place_id, int woe_id)
{
xmlDocPtr doc = NULL;
xmlXPathContextPtr xpathCtx = NULL;
void* result = NULL;
char woe_id_str[10];
flickcurl_init_params(fc, 0);
if(!photo_id)
return 1;
flickcurl_add_param(fc, "photo_id", photo_id);
flickcurl_add_param(fc, "place_id", place_id);
if(woe_id > 0) {
sprintf(woe_id_str, "%d", woe_id);
flickcurl_add_param(fc, "woe_id", woe_id_str);
}
flickcurl_end_params(fc);
if(flickcurl_prepare(fc, "flickr.photos.geo.correctLocation"))
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;
}
result = NULL; /* your code here */
tidy:
if(xpathCtx)
xmlXPathFreeContext(xpathCtx);
if(fc->failed)
result = NULL;
return (result == NULL);
}
示例11: list_dbus_properties
void list_dbus_properties(xmlDocPtr doc, GDBusConnection *bus, const gchar *dest, const gchar *path, gpointer user)
{
GHashTable *methods = user;
xmlXPathContextPtr context;
xmlXPathObjectPtr result;
xmlNodeSetPtr nodes;
context = xmlXPathNewContext(doc);
result = xmlXPathEvalExpression("/node/interface/property[@name]", context);
xmlXPathFreeContext(context);
if (!result) {
g_debug("xpath query failed for property declarations");
return;
}
if (!result->nodesetval) {
g_debug("no results for xpath query");
xmlXPathFreeObject(result);
return;
}
nodes = result->nodesetval;
for (gint i = 0; i < nodes->nodeNr; i++) {
xmlAttrPtr attrib = nodes->nodeTab[i]->properties;
gchar *property;
// Find the attribute name
while (g_strcmp0(attrib->name, "name") != 0) {
attrib = attrib->next;
g_assert(attrib);
}
property = g_strdup_printf("p:%s.%s", nodes->nodeTab[i]->parent->properties->children->content, attrib->children->content);
if (!g_hash_table_contains(methods, property)) {
g_hash_table_add(methods, property);
if (check_access_property(bus, dest, path, nodes->nodeTab[i]->parent->properties->children->content, attrib->children->content))
g_print("\t%s %s\n", property, path);
}
}
xmlXPathFreeObject(result);
return;
}
示例12: GDALGMLJP2GenerateMetadata
CPLXMLNode* GDALGMLJP2GenerateMetadata(
const CPLString& osTemplateFile,
const CPLString& osSourceFile
)
{
GByte* pabyStr = nullptr;
if( !VSIIngestFile( nullptr, osTemplateFile, &pabyStr, nullptr, -1 ) )
return nullptr;
CPLString osTemplate(reinterpret_cast<char *>(pabyStr));
CPLFree(pabyStr);
if( !VSIIngestFile( nullptr, osSourceFile, &pabyStr, nullptr, -1 ) )
return nullptr;
CPLString osSource(reinterpret_cast<char *>(pabyStr));
CPLFree(pabyStr);
xmlDocPtr pDoc = xmlParseDoc(
reinterpret_cast<const xmlChar *>(osSource.c_str()));
if( pDoc == nullptr )
{
CPLError(CE_Failure, CPLE_AppDefined, "Cannot parse %s",
osSourceFile.c_str());
return nullptr;
}
xmlXPathContextPtr pXPathCtx = xmlXPathNewContext(pDoc);
if( pXPathCtx == nullptr )
{
xmlFreeDoc(pDoc);
return nullptr;
}
xmlXPathRegisterFunc(pXPathCtx, reinterpret_cast<const xmlChar *>("if"),
GDALGMLJP2XPathIf);
xmlXPathRegisterFunc(pXPathCtx, reinterpret_cast<const xmlChar *>("uuid"),
GDALGMLJP2XPathUUID);
pXPathCtx->error = GDALGMLJP2XPathErrorHandler;
GDALGMLJP2RegisterNamespaces(pXPathCtx, xmlDocGetRootElement(pDoc));
CPLString osXMLRes = GDALGMLJP2EvalExpr(osTemplate, pXPathCtx, pDoc);
xmlXPathFreeContext(pXPathCtx);
xmlFreeDoc(pDoc);
return CPLParseXMLString(osXMLRes);
}
示例13: list_dbus_methods
void list_dbus_methods(xmlDocPtr doc, GDBusConnection *bus, const gchar *dest, const gchar *path, gpointer user)
{
GHashTable *methods = user;
xmlXPathContextPtr context;
xmlXPathObjectPtr result;
xmlNodeSetPtr nodes;
context = xmlXPathNewContext(doc);
result = xmlXPathEvalExpression("/node/interface/method[@name]", context);
xmlXPathFreeContext(context);
if (!result) {
g_debug("xpath query failed for method declarations");
return;
}
if (!result->nodesetval) {
g_debug("no results for xpath query");
xmlXPathFreeObject(result);
return;
}
nodes = result->nodesetval;
for (gint i = 0; i < nodes->nodeNr; i++) {
xmlAttrPtr attrib = nodes->nodeTab[i]->properties;
gchar *method;
method = g_strdup_printf("m:%s.%s", nodes->nodeTab[i]->parent->properties->children->content, attrib->children->content);
if (!g_hash_table_contains(methods, method)) {
g_hash_table_add(methods, method);
if (check_access_method(bus,
dest,
path,
nodes->nodeTab[i]->parent->properties->children->content,
attrib->children->content)) {
g_print("\t%s %s\n", method, path);
}
}
}
xmlXPathFreeObject(result);
return;
}
示例14: cpuTestLoadMultiXML
static virCPUDefPtr *
cpuTestLoadMultiXML(const char *arch,
const char *name,
unsigned int *count)
{
char *xml = NULL;
xmlDocPtr doc = NULL;
xmlXPathContextPtr ctxt = NULL;
xmlNodePtr *nodes = NULL;
virCPUDefPtr *cpus = NULL;
int n;
size_t i;
if (virAsprintf(&xml, "%s/cputestdata/%s-%s.xml", abs_srcdir, arch, name) < 0)
goto cleanup;
if (!(doc = virXMLParseFileCtxt(xml, &ctxt)))
goto cleanup;
n = virXPathNodeSet("/cpuTest/cpu", ctxt, &nodes);
if (n <= 0 || (VIR_ALLOC_N(cpus, n) < 0)) {
fprintf(stderr, "\nNo /cpuTest/cpu elements found in %s\n", xml);
goto cleanup;
}
for (i = 0; i < n; i++) {
ctxt->node = nodes[i];
cpus[i] = virCPUDefParseXML(nodes[i], ctxt, VIR_CPU_TYPE_HOST);
if (!cpus[i])
goto cleanup_cpus;
}
*count = n;
cleanup:
VIR_FREE(xml);
VIR_FREE(nodes);
xmlXPathFreeContext(ctxt);
xmlFreeDoc(doc);
return cpus;
cleanup_cpus:
for (i = 0; i < n; i++)
virCPUDefFree(cpus[i]);
VIR_FREE(cpus);
goto cleanup;
}
示例15: get_server_info
/* Get Info server */
static void get_server_info(const char *ident)
{
char *path = NULL;
char xpath[SIZE];
xmlXPathContextPtr xml_context = NULL;
xmlXPathObjectPtr xmlobject;
long lval;
char *ep;
(void)crv_strncpy(xpath, "/database/file[@id='", sizeof(xpath));
(void)crv_strncat(xpath, ident, sizeof(xpath));
(void)crv_strncat(xpath, "']/server" , sizeof(xpath));
path = crv_strdup(xpath);
xmlXPathInit();
xml_context = xmlXPathNewContext (xmldoc);
xmlobject = xmlXPathEval (path, xml_context);
crv_free(path);
if ((xmlobject->type == XPATH_NODESET) )
{
int j;
xmlNodePtr node;
for (j = 0; j < xmlobject->nodesetval->nodeNr; j++)
{
node = xmlobject->nodesetval->nodeTab[j];
xmlChar *Host = xmlGetProp(node, "host");
if (Host != NULL) {
server = crv_strdup(Host);
}
xmlChar *Port = xmlGetProp(node, "port");
if (Port != NULL) {
lval = strtol(Port, &ep, 10);
if (Port[0] == '\0' || *ep != '\0') {
fprintf(stderr, "%s%s", Port, " is not a number");
return;
}
port = lval;
}
xmlFree (Host);
xmlFree (Port);
}
}
xmlXPathFreeObject (xmlobject);
xmlXPathFreeContext (xml_context);
}