static int parse_attributes(elcgen *gen, xmlNodePtr elem, expression *pnode) { xmlAttrPtr attr; expression **aptr = &pnode->r.attributes; for (attr = pnode->xmlnode->properties; attr; attr = attr->next) { if ((attr->ns && strcmp((char*)attr->ns->href,XSLT_NS)) || (NULL == attr->ns)) { char *value = xmlNodeListGetString(gen->parse_doc,attr->children,1); char *tmp = (char*)malloc(strlen(value)+3); expression *newnode = new_xsltnode(pnode->xmlnode,XSLT_LITERAL_ATTRIBUTE); *aptr = newnode; aptr = &newnode->next; sprintf(tmp,"}%s{",value); newnode->qn.prefix = attr->ns ? strdup((char*)attr->ns->prefix) : strdup(""); newnode->qn.uri = attr->ns ? strdup((char*)attr->ns) : strdup(""); newnode->qn.localpart = strdup((char*)attr->name); newnode->ident = nsname_to_ident(newnode->qn.uri,newnode->qn.localpart); newnode->r.value_avt = parse_xpath(gen,newnode,tmp); free(tmp); free(value); if (NULL == newnode->r.value_avt) return 0; } } return 1; }
static int parse_avt(elcgen *gen, xmlNodePtr n, const char *attr, expression **expr, int required, expression *pnode) { char *value; char *tmp; assert(pnode->xmlnode == n); if (!xmlHasProp(n,attr)) { *expr = NULL; if (required) return gen_error(gen,"%s element missing %s attribute",n->name,attr); else return 1; } value = xmlGetProp(n,attr); if (gen->ispattern && (!strncmp(value,"#E",2))) { *expr = new_expression(XPATH_DSVAR); (*expr)->str = strdup(value+1); } else { tmp = (char*)malloc(strlen(value)+3); sprintf(tmp,"}%s{",value); *expr = parse_xpath(gen,pnode,tmp); free(tmp); } free(value); return (NULL != *expr); }
static int parse_expr_attr(elcgen *gen, xmlNodePtr n, const char *attr, expression **expr, int required, expression *pnode) { char *value; assert(pnode->xmlnode == n); if (!xmlHasProp(n,attr)) { *expr = NULL; if (required) return gen_error(gen,"%s element missing %s attribute",n->name,attr); else return 1; } value = xmlGetProp(n,attr); *expr = parse_xpath(gen,pnode,value); free(value); return (NULL != *expr); }
/********************************************************************** * FUNCTION NAME: * xpath * * DESCRIPTION: * This function return a node set (table of nodes) corresponding to a given xpath. * * INTERFACE: * GLOBAL DATA: * res_node_array--preserve the result node set * * INPUT: * n-- current node * path --the xpath to use * * OUTPUT: * None * * INPUT/OUTPUT: * node_set--the node table pointer * nb_node --the number of results * * AUTHOR: * Fu Pei * * RETURN VALUE: * * if execute xpath failed return the error type otherwise * return PROCESS_SUCCESS * * * NOTES: * *********************************************************************/ int xpath(node_t *n, char *path,node_t* ((**node_set)[MAX_XPATH_RES_REC]), int *nb_node) { int ret = PROCESS_SUCCESS; int max_xp_count = 0; int count = 0; node_t *root = n; char *full_path_to_find; /*clear res_node_array data*/ clear_array_data(res_node_array,MAX_XPATH_RES_REC); /*point to the array which satisfy the given condition*/ *node_set = &res_node_array; if (n == NULL) { ret= XPATH_ERROR; } if (ret != XPATH_ERROR) { root = get_root(n); full_path_to_find = strdup(path); /*initial the xpath array*/ init_xpath_array(); /*parse the given xpath */ max_xp_count = parse_xpath(full_path_to_find); if (max_xp_count >= 0) { /*handled xpath*/ ret = exec_xpath(root, n, max_xp_count, &count); } else { ret = XPATH_ERROR; } if (ret != XPATH_ERROR) { *nb_node = count; } } return ret; }