コード例 #1
0
int OSConfigure::openxpath ( std::string path )
{

    xmlChar * xpath = ( xmlChar * ) path.c_str ();
    xmlChar *keyword;
    std::string retstring;

    xmlXPathContextPtr context;

    context = xmlXPathNewContext ( doc );
    if ( context == NULL )
        return -1;

    result = xmlXPathEvalExpression ( xpath, context );
    xmlXPathFreeContext ( context );
    if ( result == NULL )
        return -1;


    if ( xmlXPathNodeSetIsEmpty ( result->nodesetval ) )
    {
        return -1;
    }
    nodeset = result->nodesetval;

    cur = nodeset->nodeTab[ 0 ] ->xmlChildrenNode;
    pos = 0;
    return 0;

}
コード例 #2
0
ファイル: ges-pitivi-formatter.c プロジェクト: cfoch/ges
static void
list_sources (GESFormatter * self)
{
  GESPitiviFormatterPrivate *priv = GES_PITIVI_FORMATTER (self)->priv;
  xmlXPathObjectPtr xpathObj;
  GHashTable *table;
  int size, j;
  gchar *id, *filename;
  xmlNodeSetPtr nodes;

  xpathObj = xmlXPathEvalExpression ((const xmlChar *)
      "/pitivi/factories/sources/source", priv->xpathCtx);
  nodes = xpathObj->nodesetval;

  size = (nodes) ? nodes->nodeNr : 0;
  for (j = 0; j < size; ++j) {
    table = get_nodes_infos (nodes->nodeTab[j]);
    id = (gchar *) g_hash_table_lookup (table, (gchar *) "id");
    filename = (gchar *) g_hash_table_lookup (table, (gchar *) "filename");
    g_hash_table_insert (priv->sources_table, g_strdup (id), table);
    g_hash_table_insert (priv->source_uris, g_strdup (filename),
        g_strdup (filename));
    if (self->project)
      ges_project_create_asset (self->project, filename, GES_TYPE_URI_CLIP);
  }

  xmlXPathFreeObject (xpathObj);
}
コード例 #3
0
ファイル: kc_helper.c プロジェクト: matje/ttods
int check_file_from_xpath(xmlXPathContextPtr xpath_ctx, const char *log_string, const xmlChar *file_xexpr) {
	int status = 0;
	xmlXPathObjectPtr xpath_obj;
	char* temp_char = NULL;
	char* str = NULL;

	xpath_obj = xmlXPathEvalExpression(file_xexpr, xpath_ctx);
	if(xpath_obj == NULL) {
		dual_log("ERROR: unable to evaluate xpath expression: %s", file_xexpr);
		return 1;
	}
    if (xpath_obj->nodesetval != NULL && xpath_obj->nodesetval->nodeNr > 0) {
		temp_char = (char*) xmlXPathCastToString(xpath_obj);

		/* strip off any trailing characters (needed for DSSub with cks_id) */
		str = strrchr(temp_char, ' ');
		if (str) {
			*str = 0;
		}

		status = check_file(temp_char, log_string);

        StrFree(temp_char);
	} else {
		/* Not set; return -1 so that we can test the default path */
		xmlXPathFreeObject(xpath_obj);
		return -1;
	}

    xmlXPathFreeObject(xpath_obj);
	return status;
}
コード例 #4
0
xmlNodePtr node_by_attr_val(const char* attr, char* val, const char* type, xmlXPathContextPtr &xpathCtx){
	string XPath = ((string)"//")+ ((string)type)+ ((string)"[@")+
				((string)attr)+ ((string)"='")+ ((string)val)+ ((string)"']");
	xmlNodeSetPtr node_set = xmlXPathEvalExpression(
				(const xmlChar *) XPath.c_str(), xpathCtx ) ->nodesetval;
	return( node_set && node_set->nodeNr >0 ? node_set->nodeTab[0] : NULL);
}
コード例 #5
0
ファイル: filter_mod.c プロジェクト: alexis-gruet/kt_savan
static xsltStylesheetPtr 
savan_xpath_filter_mod_get_filter_template(
    const axutil_env_t *env,
    axis2_char_t *filter_template_path,
    xmlChar *filter)
{
    xsltStylesheetPtr xslt_template_xslt = NULL;
    xmlDocPtr xslt_template_xml = NULL;
    xmlChar* xpathExpr = NULL; 
    xmlXPathContextPtr xpathCtx = NULL;
    xmlXPathObjectPtr xpathObj = NULL;
	
    AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "[savan] filter_template_path:%s", filter_template_path);

    xslt_template_xml = xmlParseFile(filter_template_path);
    xpathExpr = (xmlChar*)"//@select";
    xpathCtx = xmlXPathNewContext(xslt_template_xml);
    xpathObj = xmlXPathEvalExpression(xpathExpr, xpathCtx);
    savan_xpath_filter_mod_update_filter_template(xpathObj->nodesetval, filter);

    xslt_template_xslt = xsltParseStylesheetDoc(xslt_template_xml);

	xmlXPathFreeObject(xpathObj);
	xmlXPathFreeContext(xpathCtx);

    return xslt_template_xslt;
}
コード例 #6
0
ファイル: door.c プロジェクト: bahamas10/openzfs
/*
 * get_op_id_from_doc --
 *	    extracts an operation id through the given context ptr.
 *
 * ctext: context ptr for the original doc
 *
 * Returns an operation id if found or -1 otherwise.
 */
static int
get_op_id_from_doc(xmlXPathContextPtr ctext)
{
	xmlChar expr[ISNS_MAX_LABEL_LEN + 13];
	xmlXPathObjectPtr xpath_obj = NULL;
	int i;

	for (i = 0; op_table[i].op_str != NULL; i++) {
	    (void) xmlStrPrintf(expr, ISNS_MAX_LABEL_LEN + 13,
		XMLSTRING_CAST "%s\"%s\"]", "//*[name()=",
		op_table[i].op_str);
	    xpath_obj = xmlXPathEvalExpression(expr, ctext);
	    if ((xpath_obj) && (xpath_obj->nodesetval) &&
		(xpath_obj->nodesetval->nodeNr > 0) &&
		(xpath_obj->nodesetval->nodeTab)) {
		isnslog(LOG_DEBUG, "get_op_id_from_doc ",
		"xpath obj->nodesetval->nodeNr: %d",
		xpath_obj->nodesetval->nodeNr);
		isnslog(LOG_DEBUG, "get_op_id_from_doc", "operation: %s id: %d",
		    op_table[i].op_str, op_table[i].op_id);
		if (xpath_obj) xmlXPathFreeObject(xpath_obj);
		return (op_table[i].op_id);
	    }
	    if (xpath_obj) xmlXPathFreeObject(xpath_obj);
	}

	if (xpath_obj) xmlXPathFreeObject(xpath_obj);
	return (-1);
}
コード例 #7
0
ファイル: specparser.cpp プロジェクト: larspm/optfir
  xmlXPathObjectPtr getNodeSet(xmlDocPtr doc, xmlChar *xpath)
  {
    xmlXPathContextPtr context;
    xmlXPathObjectPtr result;

    context = xmlXPathNewContext(doc);

    if (context == NULL)
    {
      return NULL;
    }

    result = xmlXPathEvalExpression(xpath, context);
    xmlXPathFreeContext(context);

    if (result == NULL)
    {
      return NULL;
    }

    if(xmlXPathNodeSetIsEmpty(result->nodesetval))
    {
      xmlXPathFreeObject(result);
      return NULL;
    }

    return result;
  }
コード例 #8
0
ファイル: CXML.cpp プロジェクト: Ntels-sup/SRC_ATOM_BE
int CXML::GetNodeFromXPath(const char *a_chPath, xmlNodePtr *a_pstNode)
{
		xmlXPathObjectPtr pPathObj = NULL;
		xmlNodeSetPtr pNodeSet = NULL;
		xmlNodePtr pNode = NULL;

		pPathObj = xmlXPathEvalExpression((const xmlChar*)a_chPath, m_stCtx);
		if(pPathObj == NULL){
				XML_LOG(XML_ERR,"XPath parsing failed(path=%s, name=%s)\n", a_chPath, a_chAttrName);
				return XML_XPATH_PARSING_FAILED;
		}

		if(pPathObj->nodesetval == NULL){
				XML_LOG(XML_ERR,"NodeSet not exit(path=%s, name=%s)\n", a_chPath, a_chAttrName);
				return XML_NODE_SET_NOT_EXIST;
		}
		pNodeSet = pPathObj->nodesetval;

		if(pNodeSet->nodeTab == NULL){
				XML_LOG(XML_ERR,"Node not exit(path=%s, name=%s)\n", a_chPath, a_chAttrName);
				return XML_NODE_NOT_EXIST;
		}
		pNode = pNodeSet->nodeTab[0];
		if(pNode == NULL){
				XML_LOG(XML_ERR,"Node not exit(path=%s, name=%s)\n", a_chPath, a_chAttrName);
				return XML_NODE_NOT_EXIST;
		}

		*a_pstNode = pNode;

		return XML_OK;
}
コード例 #9
0
xmlXPathObject *osync_xml_get_nodeset(xmlDoc *doc, const char *expression)
{
	xmlXPathContext *xpathCtx = NULL;
	xmlXPathObject *xpathObj = NULL;
		
	/* Create xpath evaluation context */
	xpathCtx = xmlXPathNewContext(doc);
	if(xpathCtx == NULL) {
		fprintf(stderr,"Error: unable to create new XPath context\n");
		return NULL;
	}
		
	/* Evaluate xpath expression */
	xpathObj = xmlXPathEvalExpression((xmlChar*)expression, xpathCtx);
	if(xpathObj == NULL) {
		fprintf(stderr,"Error: unable to evaluate xpath expression \"%s\"\n", expression);
		xmlXPathFreeContext(xpathCtx); 
		return NULL;
	}

	xmlXPathFreeContext(xpathCtx);
	/* Cleanup of XPath data */
	// xmlXPathFreeObject(xpathObj);
	return xpathObj;
}
コード例 #10
0
CFArrayRef VMKXMLPathProcessorEvaluateExpression(VMKXMLPathProcessorRef processor, const char *expression)
{
    assert(processor);
    
    xmlXPathObjectPtr xpathObject = xmlXPathEvalExpression((xmlChar *)expression, processor->_rawXMLPathContext);
	
	xmlNodeSetPtr nodes = xpathObject->nodesetval;
	
    CFMutableArrayRef results = NULL;
    
    if (nodes)
    {
        
        results = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);
        
        int looper = 0;
        while (looper < nodes->nodeNr)
        {
            VMKXMLNodeRef node = VMKXMLNodeCreate(nodes->nodeTab[looper]);
            
            CFArrayAppendValue(results, node);
            
            CFRelease(node);
            
            ++looper;
        }
        
    }
    
    xmlXPathFreeObject(xpathObject);
    
    CFMakeCollectable(results);
    
    return results;
}
コード例 #11
0
static Bool
initXPathFromMetadataPath (CompXPath	 *xPath,
			   CompMetadata  *metadata,
			   const xmlChar *path)
{
    xmlXPathObjectPtr  obj;
    xmlXPathContextPtr ctx;
    int		       i;

    for (i = 0; i < metadata->nDoc; i++)
    {
	ctx = xmlXPathNewContext (metadata->doc[i]);
	if (ctx)
	{
	    obj = xmlXPathEvalExpression (path, ctx);
	    if (obj)
	    {
		if (obj->nodesetval && obj->nodesetval->nodeNr)
		{
		    xPath->ctx = ctx;
		    xPath->obj = obj;
		    xPath->doc = metadata->doc[i];

		    return TRUE;
		}

		xmlXPathFreeObject (obj);
	    }

	    xmlXPathFreeContext (ctx);
	}
    }

    return FALSE;
}
コード例 #12
0
ファイル: config.cpp プロジェクト: bacek/xscript
std::string
XmlConfig::value(const std::string &key) const {

    std::string res;

    XmlXPathContextHelper xctx(xmlXPathNewContext(data_->doc_.get()));
    XmlUtils::throwUnless(NULL != xctx.get());

    XmlXPathObjectHelper object(xmlXPathEvalExpression((const xmlChar*) key.c_str(), xctx.get()));
    XmlUtils::throwUnless(NULL != object.get());

    if (NULL != object->nodesetval && 0 != object->nodesetval->nodeNr) {

        xmlNodeSetPtr ns = object->nodesetval;
        XmlUtils::throwUnless(NULL != ns->nodeTab[0]);
        const char *val = XmlUtils::value(ns->nodeTab[0]);
        if (NULL != val) {
            res.assign(val);
        }
    }
    else {
        std::stringstream stream;
        stream << "nonexistent config param: " << key;
        throw std::runtime_error(stream.str());
    }
    data_->resolveVariables(res);
    return res;
}
コード例 #13
0
ファイル: config.cpp プロジェクト: bacek/xscript
void
XmlConfig::XmlConfigData::findVariables(const XmlDocHelper &doc) {

    XmlXPathContextHelper xctx(xmlXPathNewContext(doc.get()));
    XmlUtils::throwUnless(NULL != xctx.get());

    XmlXPathObjectHelper object(xmlXPathEvalExpression((const xmlChar*) "/xscript/variables/variable", xctx.get()));
    XmlUtils::throwUnless(NULL != object.get());

    if (NULL != object->nodesetval && 0 != object->nodesetval->nodeNr) {
        xmlNodeSetPtr ns = object->nodesetval;
        for (int i = 0; i < ns->nodeNr; ++i) {

            xmlNodePtr node = ns->nodeTab[i];
            XmlUtils::throwUnless(NULL != node);

            const char *val = XmlUtils::value(node);
            const char *name = XmlUtils::attrValue(node, "name");
            if (NULL == val || NULL == name) {
                throw std::logic_error("bad variable definition");
            }
            vars_.insert(std::pair<std::string, std::string>(name, val));
        }
    }
}
コード例 #14
0
ファイル: libxml_util.cpp プロジェクト: hatc/image-proxy
bool XmlDocument::XPath(StringPiece const &v, std::wstring *r) {
  WStringPiece str;
  xmlXPathObjectPtr xpath = xmlXPathEvalExpression((unsigned char const*)v.data(), libxml_stuff->xpath_context);
  if (xpath) {
    xmlChar *s_ = xmlXPathCastToString(xpath);
    if (s_) {
      StringPiece s((char*)s_);
      wchar_t *output = conv_buf.Alloc(s.length());
      int const conv_result = cpcl::TryConvertUTF8_UTF16(s, output, conv_buf.Size());
      if (conv_result == -1) {
        output = 0;
        Trace(CPCL_TRACE_LEVEL_ERROR, "XmlDocument::XPath(%s): utf_to_uc fails", v.as_string().c_str());
      }
      else {
        output = conv_buf.Data() + conv_result;
        if (conv_result > ((int)(conv_buf.Size()&INT_MAX)))
          Trace(CPCL_TRACE_LEVEL_WARNING, "XmlDocument::XPath(%s): TryConvertUTF8_UTF16 okashi desu ne...", v.as_string().c_str());
      }

      xmlFree(s_);
      if (output) {
        //*output = 0;
        str = WStringPiece(conv_buf.Data(), output - conv_buf.Data());
      }
    }
    xmlXPathFreeObject(xpath);
  }

  if (TrimResults)
    str = str.trim(TrimChars);

  if ((!str.empty()) && (r))
    r->assign(str.data(), str.size());
  return (!str.empty());
}
コード例 #15
0
ファイル: xbrlGetImportNames.cpp プロジェクト: cran/XBRL
RcppExport SEXP xbrlGetImportNames(SEXP epaDoc) {
  xmlDocPtr doc = (xmlDocPtr) R_ExternalPtrAddr(epaDoc);

  xmlXPathContextPtr context = xmlXPathNewContext(doc);
  xmlXPathObjectPtr import_res = xmlXPathEvalExpression((xmlChar*) "//*[local-name()='import']", context);
  xmlNodeSetPtr import_nodeset = import_res->nodesetval;
  xmlXPathFreeContext(context);

  int import_nodeset_ln = import_nodeset->nodeNr;

  CharacterVector schemaLocation(import_nodeset_ln);

  for (int i=0; i < import_nodeset_ln; i++) {
    xmlNodePtr import_node = import_nodeset->nodeTab[i];

    xmlChar *tmp_str;
    if ((tmp_str = xmlGetProp(import_node, (xmlChar*) "schemaLocation"))) { 
      schemaLocation[i] = (char *) tmp_str;
      xmlFree(tmp_str);
    } else {
      schemaLocation[i] = NA_STRING;
    }
  }
  xmlXPathFreeObject(import_res);

  return schemaLocation;
}
コード例 #16
0
ファイル: grl-raitv.c プロジェクト: kyoushuu/grilo-plugins
static gchar *
eval_xquery (const gchar *xquery,
             xmlXPathContextPtr xpath)
{
    int i;
    xmlChar *szValue;
    xmlNodePtr curNode;
    xmlNodeSetPtr nodeset;
    xmlXPathObjectPtr xobj;

    xobj = xmlXPathEvalExpression ((xmlChar *) xquery, xpath);

    if(xobj != NULL) {
        nodeset = xobj->nodesetval;
        for (i = 0; i < nodeset->nodeNr; i++) {
            curNode = nodeset->nodeTab[i];
            if(curNode != NULL)
            {
                szValue = xmlGetProp(curNode,BAD_CAST "content");
                if (szValue != NULL)
                {
                    xmlXPathFreeObject (xobj);
                    return (gchar *) szValue;
                }
            }
        }
        xmlXPathFreeObject (xobj);
    }

    return NULL;
}
コード例 #17
0
int parse(xmlDocPtr xml_doc, const xmlChar* xpathExpr) {
    xmlXPathContextPtr xpathCtx; 
    xmlXPathObjectPtr xpathObj; 
    
    assert(xml_doc);
    assert(xpathExpr);

    /* Create xpath evaluation context */
    if (! (xpathCtx = xmlXPathNewContext(xml_doc))) {
        printf("Failed to create new XPath context\n"); 
        return -1;
    }
    
    /* Evaluate xpath expression */
    if (! (xpathObj = xmlXPathEvalExpression(xpathExpr, xpathCtx))) {
        printf("Failed to evaluate xpath expression \"%s\"\n", xpathExpr);
        xmlXPathFreeContext(xpathCtx); 
        return -1;
    }
    
    /* update selected nodes */
    parse_nodes(xpathObj->nodesetval);

    /* Cleanup of XPath data */
    xmlXPathFreeObject(xpathObj);
    xmlXPathFreeContext(xpathCtx); 
    
    return(0);
}
コード例 #18
0
ファイル: nmp_xml_fun.c プロジェクト: dulton/nampu
/**
 * nmp_get_node: parse an XML in-memory document and build a tree.
 *
 * @doc:    input, a pointer to document tree
 * @xpath:  input, addressing parts of an XML document
 * @return: the resulting document tree, else NULL
 */
xmlXPathObjectPtr 
nmp_get_node(xmlDocPtr doc, const xmlChar *xpath)
{
    xmlXPathContextPtr context;
    xmlXPathObjectPtr result;
    
    context = xmlXPathNewContext(doc);
    if (context == NULL) 
    {
        xml_error("context is NULL\n");
        return NULL; 
    }
    
    result = xmlXPathEvalExpression(xpath, context);
    xmlXPathFreeContext(context);
    if (result == NULL)
    {
        xml_error("xmlXPathEvalExpression return NULL\n"); 
        return NULL; 
    }
    
    if (xmlXPathNodeSetIsEmpty(result->nodesetval)) 
    {
        xmlXPathFreeObject(result);
        xml_error("nodeset is empty\n");
        return NULL;
    }
    
    return result;
}
コード例 #19
0
ファイル: xml_tool.cpp プロジェクト: klampworks/mammon
int run_xpath(xmlDoc *doc, const char *xpath)
{
	xmlXPathContext *xpath_ctx = xmlXPathNewContext(doc);
	if (!xpath_ctx) {
		printf("Could not create new xpath context.\n");
		//xmlFreeDoc(doc);
		return 1;
	}

	xmlChar *xml_xpath = xmlCharStrdup(xpath);
	xmlXPathObject *xpath_obj = xmlXPathEvalExpression(xml_xpath, xpath_ctx);
	if (!xpath_obj) {
		puts("Could not evaluate xpath expression.\n");
		free(xml_xpath);
		return 1;
	}

    assert(xpath_obj->nodesetval->nodeTab);
    for (auto n = *xpath_obj->nodesetval->nodeTab; n; n = n->next) {
        printf("----------------------------------------"
                "----------------------------------------\n");
        print_element_names(n, 0);
        printf("----------------------------------------"
                "----------------------------------------\n");
    }

	//xmlXPathFreeObject(xpath_obj);
	free(xml_xpath);

	//xmlXPathFreeContext(xpath_ctx); 
	//xmlFreeDoc(doc);
	return 0;
}
コード例 #20
0
ファイル: wiki.c プロジェクト: maxux/z03
char *wiki_head(char *url) {
	curl_data_t *curl;
	xmlDoc *doc = NULL;
	xmlXPathContext *ctx = NULL;
	xmlXPathObject *xpathObj = NULL;
	char *text = NULL;
	
	curl = curl_data_new();
	
	if(curl_download_text(url, curl))
		return NULL;
	
	doc = (xmlDoc *) htmlReadMemory(curl->data, strlen(curl->data), "/", "utf-8", HTML_PARSE_NOERROR);
	
	/* creating xpath request */
	ctx = xmlXPathNewContext(doc);
	xpathObj = xmlXPathEvalExpression((const xmlChar *) "//div[@id='mw-content-text']/p", ctx);
	
	if(!xmlXPathNodeSetIsEmpty(xpathObj->nodesetval)) {
		if(xmlNodeGetContent(xpathObj->nodesetval->nodeTab[0]))
			text = strdup((char *) xmlNodeGetContent(xpathObj->nodesetval->nodeTab[0]));	
	}

	xmlXPathFreeObject(xpathObj);
	xmlXPathFreeContext(ctx);
	xmlFreeDoc(doc);
	curl_data_free(curl);
	
	return text;
}
コード例 #21
0
// Evaluate an XPath expression and return matching Nodes.
NodeList Document::findXPath(const std::string& path) const
{
    // Set up the XPath context
    xmlXPathContextPtr context = xmlXPathNewContext(_xmlDoc);

    if (context == NULL) {
        std::cerr << "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) {
        std::cerr << "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;
}
コード例 #22
0
ファイル: utils.c プロジェクト: UIKit0/libgrss
static xmlNodePtr
xhtml_find_body (xmlDocPtr doc)
{
	xmlXPathContextPtr xpathCtxt = NULL;
	xmlXPathObjectPtr xpathObj = NULL;
	xmlNodePtr node = NULL;

	xpathCtxt = xmlXPathNewContext (doc);
	if (!xpathCtxt)
		goto error;

	xpathObj = xmlXPathEvalExpression (BAD_CAST"/html/body", xpathCtxt);
	if (!xpathObj)
		goto error;
	if (!xpathObj->nodesetval->nodeMax)
		goto error;

	node = xpathObj->nodesetval->nodeTab[0];

error:
	if (xpathObj)
		xmlXPathFreeObject (xpathObj);
	if (xpathCtxt)
		xmlXPathFreeContext (xpathCtxt);

	return node;
}
コード例 #23
0
ファイル: xml_settings.cpp プロジェクト: Leonya/xiva
void
xml_settings::find_variables() {

	xml::xpath_context ctx(xmlXPathNewContext(doc_.get()));
	xml::throw_unless(ctx);

	xml::xpath_object object(xmlXPathEvalExpression((xmlChar const*) "/" XIVA_PACKAGE_NAME "/variables/variable", ctx.get()));
	xml::throw_unless(object);

	xmlNodeSetPtr ns = object->nodesetval;
	if (!ns || 0 == ns->nodeNr) {
		return;
	}

	for (std::size_t i = 0; i < static_cast<std::size_t>(ns->nodeNr); ++i) {
		xmlNodePtr node = ns->nodeTab[i];
		xml::throw_unless(node);

		char const *val = xml::text_value(node);
		char const *name = xml::attr_value(node, "name");

		if (name && val) {
			vars_->add_variable(name, val);
		}
		else throw error("bad variable definition");
	}
}
コード例 #24
0
ファイル: xbrlGetSchemaName.cpp プロジェクト: horndog/XBRL
RcppExport SEXP xbrlGetSchemaName(SEXP epaDoc) {
  xmlDocPtr doc = (xmlDocPtr) R_ExternalPtrAddr(epaDoc);

  xmlXPathContextPtr context = xmlXPathNewContext(doc);
  xmlXPathObjectPtr schemaRef_res = xmlXPathEvalExpression((xmlChar*) "//*[local-name()='schemaRef']", context);
  xmlNodeSetPtr schemaRef_nodeset = schemaRef_res->nodesetval;
  xmlXPathFreeContext(context);

  int schemaRef_nodeset_ln = schemaRef_nodeset->nodeNr;

  CharacterVector href(schemaRef_nodeset_ln);

  for (int i=0; i < schemaRef_nodeset_ln; i++) {
    xmlNodePtr schemaRef_node = schemaRef_nodeset->nodeTab[i];

    xmlChar *tmp_str;
    if ((tmp_str = xmlGetProp(schemaRef_node, (xmlChar*) "href"))) { 
      href[i] = (char *) tmp_str;
      xmlFree(tmp_str);
    } else {
      href[i] = NA_STRING;
    }
  }
  xmlXPathFreeObject(schemaRef_res);

  return href;
}
コード例 #25
0
ファイル: ges-pitivi-formatter.c プロジェクト: cfoch/ges
static gboolean
pitivi_can_load_uri (GESFormatter * dummy_instance, const gchar * uri,
    GError ** error)
{
  xmlDocPtr doc;
  gboolean ret = TRUE;
  xmlXPathObjectPtr xpathObj;
  xmlXPathContextPtr xpathCtx;
  gchar *filename = g_filename_from_uri (uri, NULL, NULL);

  if (!g_file_test (filename, G_FILE_TEST_EXISTS)) {
    g_free (filename);
    return FALSE;
  }

  g_free (filename);

  if (!(doc = xmlParseFile (uri))) {
    GST_ERROR ("The xptv file for uri %s was badly formed", uri);
    return FALSE;
  }

  xpathCtx = xmlXPathNewContext (doc);
  xpathObj = xmlXPathEvalExpression ((const xmlChar *) "/pitivi", xpathCtx);
  if (!xpathObj || !xpathObj->nodesetval || xpathObj->nodesetval->nodeNr == 0)
    ret = FALSE;

  xmlFreeDoc (doc);
  xmlXPathFreeObject (xpathObj);
  xmlXPathFreeContext (xpathCtx);

  return ret;
}
コード例 #26
0
ファイル: ipfixconf.c プロジェクト: VisBlank/ipfixcol
/**
 * \brief Get plugin node by its type and name
 */
xmlNodePtr get_plugin(conf_info_t *info, char *tag, char *nametag, char *nameval)
{
	xmlChar *xpath = NULL;
	xmlXPathObjectPtr result;
	xmlNodePtr plug = NULL;
	
	/* Check if plugin already exists */
	if (asprintf((char **) &xpath, "/cesnet-ipfixcol-int:ipfixcol/cesnet-ipfixcol-int:%s", tag) == -1) {
		fprintf(stderr, "Unable to allocate memory for asprintf!\n");
		return NULL;
	}
	
	result = xmlXPathEvalExpression(xpath, info->ctxt);
	free(xpath);
	
	if (!result) {
		fprintf(stderr, "xmlXPathEvalExpression failed\n");
		return NULL;
	}
	
	if (!xmlXPathNodeSetIsEmpty(result->nodesetval)) {
		plug = get_node(result, nameval, nametag);
	}
	xmlXPathFreeObject(result);
	
	return plug;
}
コード例 #27
0
ファイル: annot_test.c プロジェクト: ericprud/libxml-annot
/*
 * This is called by ??? when reading an annotation is encountered
 * while reading the instance data.
 */
xmlParserErrors instance_annotation_callback(void *handle, xmlNodePtr node)
{
    int i;
    char key[20];
    xmlChar* path;
    xmlDocPtr doc = node->doc;
    xmlXPathContextPtr xpathCtx = xmlXPathNewContext(doc);
    xmlXPathObjectPtr xpathObj;

    sprintf(key, "%p", handle);
    path = (xmlChar*)xmlHashLookup(Handle2Path, (xmlChar*)key);
    assert(path != NULL);

    printf("\noooooooooooo %s: %p\n", __FUNCTION__, handle);
    dump_doc(node->doc, node);
    /* walk_doc_tree(node, 0); */
    printf("\n");
    xpathCtx->node = node;
    xpathObj = xmlXPathEvalExpression(path, xpathCtx);
    if (xpathObj->nodesetval != NULL)
	for (i = 0; i < xpathObj->nodesetval->nodeNr; ++i)
	    printf("xpath(\"%s\") => %s\n", path,
		   xmlNodeGetContent(xpathObj->nodesetval->nodeTab[i]));
    return XML_ERR_OK;
}
コード例 #28
0
xmlNodeSetPtr getXNodes(xmlXPathContextPtr context, const gchar *xpath) {
  xmlXPathObjectPtr xobj = xmlXPathEvalExpression(BAD_CAST(xpath), context);
  xmlNodeSetPtr ret = xobj->nodesetval;
  xmlXPathFreeNodeSetList(xobj);

  return ret;
}
コード例 #29
0
ファイル: kc_helper.c プロジェクト: matje/ttods
int check_path_from_xpath(xmlXPathContextPtr xpath_ctx, const char *log_string, const xmlChar *path_xexpr) {
	int status = 0;
	xmlXPathObjectPtr xpath_obj;
	char* temp_char = NULL;

	xpath_obj = xmlXPathEvalExpression(path_xexpr, xpath_ctx);
	if(xpath_obj == NULL) {
		dual_log("ERROR: unable to evaluate xpath expression: %s", path_xexpr);
		return 1;
	}
    if (xpath_obj->nodesetval != NULL && xpath_obj->nodesetval->nodeNr > 0) {
		temp_char = (char*) xmlXPathCastToString(xpath_obj);

		status = check_path(temp_char, log_string);

        StrFree(temp_char);
	} else {
		/* Not set; return -1 so that we can test the default path */
		xmlXPathFreeObject(xpath_obj);
		return -1;
	}

    xmlXPathFreeObject(xpath_obj);
	return status;
}
コード例 #30
0
bool OSConfigure::addstring ( std::string path, std::string node, std::string value )
{
    xmlChar * xpath = ( xmlChar * ) path.c_str ();
    xmlChar *keyword;
    std::string retstring;


    xmlNodeSetPtr nodeset;
    xmlXPathContextPtr context;
    xmlXPathObjectPtr result;

    context = xmlXPathNewContext ( doc );
    if ( context == NULL )
        return false;

    result = xmlXPathEvalExpression ( xpath, context );
    xmlXPathFreeContext ( context );
    if ( result == NULL )
        return false;


    if ( xmlXPathNodeSetIsEmpty ( result->nodesetval ) )
    {
        return false;
    }

    nodeset = result->nodesetval;

    xmlNewChild ( nodeset->nodeTab[ 0 ], NULL, ( xmlChar * ) node.c_str (), ( xmlChar * ) value.c_str () );

    xmlXPathFreeObject ( result );

    return true;

}