Axiom XPath API
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:
axiom_xpath_expression_t *exp = axiom_xpath_compile_expression(env, "/father/son");
Create XPath Context
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
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* result = axiom_xpath_select_nodes(env, root, exp);
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;
}struct axiom_xpath_result_node
{
axiom_xpath_result_type type;
void * value;
}
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.