Dear Wiki user, You have subscribed to a wiki page or wiki category on "Ws Wiki" for change notification.
The following page has been changed by VarunaJayasiri: http://wiki.apache.org/ws/axiom-xpath-api-gsoc-varuna ------------------------------------------------------------------------------ - == Axiom XPath API == + = Axiom XPath API = - This is not intended to be a comprehensive API documentation, but an overview of proposed API for Google Summer of Code project. + ==== Compile XPath Expression ==== + {{{ + axiom_xpath_expression_t* axiom_xpath_compile_expression(const axutil_env_t *env, const axis2_char_t* xpath_expr) + }}} + Creates a axiom_xpath_expression by parsing xpath_expr. All parse errors will be handled by this function. All parse errors will be logged if necessary. + ''Example:'' - == Functions == - - ==== axiom_xpath_expression_t* axiom_xpath_create_expression(const axutil_env_t *env, const axis2_char_t* xpath_expr) ==== - Creates a axiom_xpath_expression by parsing xpath_expr. All parse errors will be handled by this function. All parse errors will be logged if necessary. - ===== Example: ===== {{{ - axiom_xpath_expression_t *exp = axiom_xpath_create_expression(env, "/father/son"); + axiom_xpath_expression_t *exp = axiom_xpath_compile_expression(env, "/father/son"); }}} + ==== Create XPath Context ==== - ==== axiom_xpath_namespace_list* axiom_xpath_create_namespace_list(const axutil_env_t *env) ==== - Creates an empty axiom_xpath_namespace_list. This will be used to register namespaces. - ===== Example: ===== {{{ - axiom_xpath_namespace_list *namespaces = axiom_xpath_create_namespace_list(env); + axiom_xpath_context_t* axiom_xpath_context_create(const axutil_env_t *env, const axiom_node_t * root_node) + }}} + Creates a XPath context for the root node. + + ==== Register Namespaces ==== + {{{ + void axiom_xpath_register_namespaces(axiom_xpath_context_t *context, const axis2_char_t* prefix, const axis2_char_t* uri) + }}} + Adds namespace to list of namespaces. + + ''Example:'' + {{{ + axiom_xpath_register_namespace(context, "red", "http://www.xvpj.net/red"); }}} + ==== Evaluate XPath Query ==== - ==== void axiom_xpath_register_namespace(const axutil_env_t *env, axiom_xpath_namespace_list * namespaces, const axis2_char_t* prefix, const axis2_char_t* uri) ==== - Adds an namespace to list of namespaces. - ===== Example:: ===== {{{ - axiom_xpath_register_namespace(env, namespaces, "red", "http://www.xvpj.net/red"); + axiom_xpath_result_t* axiom_xpath_evaluate(axiom_xpath_context_t *context, const axiom_xpath_expression_t * xpath_expr) }}} + Evaluates the xpath expression and return the results. + ''Example:'' - ==== axiom_xpath_result_t* axiom_xpath_evaluate(const axutil_env_t *env, const axiom_node_t * root_node, const axiom_xpath_expression_t * xpath_expr, const axiom_xpath_namespace_list * namespaces = NULL) ==== - Evaluates the xpath expression and return the results. - ===== Example:: ===== {{{ axiom_xpath_result_t* result = axiom_xpath_select_nodes(env, root, exp); }}} - ---- - ''It is also possible to use a xpath context (as in libxml xpath module) where the context is initialized with the root node and then namespaces are registered'' - ==== axiom_xpath_result_type_t axiom_xpath_get_result_type(axiom_xpath_result_t * result) ==== - Gets the type of result obtained by evaluating the xpath expression. This could be a string, number, boolean, node or a list of nodes. + ==== XPath Result ==== + {{{ + struct axiom_xpath_result + { + int size; // Number of nodes in the result set + int flag; // For error messages, etc + axiom_xpath_result_node_t * nodes; + } + }}} - ==== axiom_node_t* axiom_xpath_get_node(axiom_xpath_result_t * result) ==== - Returns the axiom node in the result. If the type of result is not node, NULL will be returned. + {{{ + struct axiom_xpath_result_node + { + axiom_xpath_result_type type; + void * value; + } + }}} - ===== Other functions to process results ===== - Other functions to process the results will have a similar interface + ==== Casting ==== + {{{ + axis2_char_t * axiom_xpath_cast_node2string(axiom_xpath_result_node_t * node) + }}} + The cast depends on the type of the node This could be a string, number, boolean, or a node. + If it is a string, it would be simply returned. + If it is a number or a boolean it will be converted to a string. + If it is a axiom node, the node and it's content will be returned as a string. + {{{ + int axiom_xpath_cast_node2boolean(axiom_xpath_result_node_t * node) + }}} + If the result is boolean it will be returned. + Otherwise true will be returned if the result is not empty. + + {{{ + double axiom_xpath_cast_node2number(axiom_xpath_result_node_t * node) + }}} + If the result is a numebr it will be returned. + If the result is boolean, 1 will be returned if true, 0 otherwise. + 0 will be returned if the result type is string or axiom node. + + {{{ + axiom_node_t * axiom_xpath_cast_node2axiom_node(axiom_xpath_result_node_t * node) + }}} + If the result type is node it will be casted and returned; otherwise, NULL will be returned. + + ==== Freeing Memory ==== + + {{{ + void axiom_xpath_free_context(axiom_xpath_context_t *context) + }}} + Frees the xpath context + + {{{ + void axiom_xpath_free_expression(axiom_xpath_expression_t * xpath_expr) + }}} + Frees the xpath expression + + {{{ + void axiom_xpath_free_result(axiom_xpath_result_t* result) + }}} + Frees the xpath result set. If result set contains axiom nodes they will not be freed as they are just pointers to the nodes in the XML tree. + --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
