You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by du...@apache.org on 2008/10/06 01:32:42 UTC
svn commit: r701901 [3/3] - in
/webservices/axis2/branches/c/xpath_integration/axiom: ./ include/ src/
src/om/ src/xpath/ test/xpath/
Added: webservices/axis2/branches/c/xpath_integration/axiom/test/xpath/test.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/xpath_integration/axiom/test/xpath/test.xml?rev=701901&view=auto
==============================================================================
--- webservices/axis2/branches/c/xpath_integration/axiom/test/xpath/test.xml (added)
+++ webservices/axis2/branches/c/xpath_integration/axiom/test/xpath/test.xml Sun Oct 5 16:32:41 2008
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+
+<test xmlns:ns1="http://xpath/test">
+
+ <ns1:node1 xmlns:nsx="http://xpath/test" attr1="attribute_value_1">10</ns1:node1>
+
+ <ns1:node2>
+ <child>1<grandchild>1</grandchild></child>
+ <child>2<grandchild>2</grandchild></child>
+ <child xmlns:ns44="http://xpath/testsasd">3<grandchild>3</grandchild></child>
+ <child>4<grandchild>4</grandchild></child>
+ <child>5<grandchild>5</grandchild></child>
+ <child>6<grandchild>6</grandchild></child>
+ <child>7<grandchild>7</grandchild></child>
+ <child>8<grandchild>8</grandchild></child>
+ <child>9<grandchild>9</grandchild></child>
+ <child>10<grandchild>10</grandchild></child>
+ <child>11<grandchild>11</grandchild></child>
+ <child>12<grandchild>12</grandchild></child>
+ <child>13<grandchild>13</grandchild></child>
+ <child>14<grandchild>14</grandchild></child>
+ <child>15<grandchild>15</grandchild></child>
+ <child>16<grandchild>16</grandchild></child>
+ <child>17<grandchild>17</grandchild></child>
+ <child>18<grandchild>18</grandchild></child>
+ <child>19<grandchild>19</grandchild></child>
+ <child>20<grandchild>20</grandchild></child>
+ </ns1:node2>
+
+ <node1 xmlns:nsp="http://xpath/test" attr1="attribute_value_2">5</node1>
+
+ <node2>
+ <child>1<grandchild>1</grandchild></child>
+ <child>2<grandchild>2</grandchild></child>
+ <child>3<grandchild>3</grandchild></child>
+ <child>4<grandchild>4</grandchild></child>
+ <child>5<grandchild>5</grandchild></child>
+ <child>6<grandchild>6</grandchild></child>
+ <child>7<grandchild>7</grandchild></child>
+ <child>8<grandchild>8</grandchild></child>
+ <child>9<grandchild>9</grandchild></child>
+ <child>10<grandchild>10</grandchild></child>
+ <child>11<grandchild>11</grandchild></child>
+ <child>12<grandchild>12</grandchild></child>
+ <child>13<grandchild>13</grandchild></child>
+ <child>14<grandchild>14</grandchild></child>
+ <child>15<grandchild>15</grandchild></child>
+ <child>16<grandchild>16</grandchild></child>
+ <child>17<grandchild>17</grandchild></child>
+ <child>18<grandchild>18</grandchild></child>
+ <child>19<grandchild>19</grandchild></child>
+ <child>20<grandchild>20</grandchild></child>
+ </node2>
+
+</test>
Added: webservices/axis2/branches/c/xpath_integration/axiom/test/xpath/test.xpath
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/xpath_integration/axiom/test/xpath/test.xpath?rev=701901&view=auto
==============================================================================
--- webservices/axis2/branches/c/xpath_integration/axiom/test/xpath/test.xpath (added)
+++ webservices/axis2/branches/c/xpath_integration/axiom/test/xpath/test.xpath Sun Oct 5 16:32:41 2008
@@ -0,0 +1,39 @@
+#Test: Functions
+test/descendant::child
+count(test/descendant::child)
+#Test: Axes
+test/node2/child::child[5]
+test/descendant::child
+test/node2/parent::*
+test/node2/child[3]/grandchild/ancestor::*
+test/node2/child[3]/following-sibling::*
+test/node2/child[3]/preceding-sibling::*
+test/node2/child[3]/following::*
+test/node2/child[3]/preceding::*
+test/*/attribute::*
+test/*/namespace::*
+test/node1/self::*
+test/descendant-or-self::child
+test/node2/child[4]/grandchild/ancestor-or-self::child
+#Test: Namespaces
+test/test:node2//grandchild
+test/test:node2/child
+test/test:node2/*
+#Test: Attributes and Predicates
+test/node1/@*
+//*[@*]
+//*[@attr1 = 'attribute_value_1']
+test/node2/child[grandchild = /test/node1]
+#Test: Equality Expressions
+test/node1 = test/node2/child
+#Test: Abbreviated Axes
+test/node2//grandchild
+test/node2/child
+test/node2/*
+#Test: Random
+test/*[@*]
+test/node2
+test/test:node2
+test/test:node1/@*
+#Test: Parse error
+//*[@]
Added: webservices/axis2/branches/c/xpath_integration/axiom/test/xpath/test_linux.c
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/xpath_integration/axiom/test/xpath/test_linux.c?rev=701901&view=auto
==============================================================================
--- webservices/axis2/branches/c/xpath_integration/axiom/test/xpath/test_linux.c (added)
+++ webservices/axis2/branches/c/xpath_integration/axiom/test/xpath/test_linux.c Sun Oct 5 16:32:41 2008
@@ -0,0 +1,478 @@
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+Compiling For Windows:
+cl.exe /nologo /D "WIN32" /D "_WINDOWS" /D "_MBCS" /I %AXIS2C_HOME%\include /c *.c
+link.exe /LIBPATH:%AXIS2C_HOME%\lib axutil.lib axiom.lib axis2_parser.lib axis2_engine.lib /OUT:test.exe *.obj
+*/
+#include <stdio.h>
+#include <axiom.h>
+#include <axis2_util.h>
+#include <axiom_soap.h>
+#include <axis2_client.h>
+
+#include "xpath.h"
+
+/* Function headers */
+axiom_node_t *build_test_xml(const axutil_env_t *env);
+
+void output_results(const axutil_env_t *env, axiom_xpath_result_t *xpath_result);
+
+axiom_node_t *read_test_xml(const axutil_env_t *env, char *file_name);
+
+void output_results(const axutil_env_t *env,
+ axiom_xpath_result_t *xpath_result);
+
+void evaluate(const axutil_env_t *env,
+ axiom_xpath_context_t *context,
+ axis2_char_t *expr_str);
+
+void evaluate_expressions(const axutil_env_t *env,
+ axiom_xpath_context_t *context,
+ char *file_name);
+
+void add_namespaces(const axutil_env_t *env,
+ axiom_xpath_context_t *context,
+ char *file_name);
+
+int readline(FILE *fin, char *str);
+
+int main(int argc, char *argv[])
+{
+ axiom_node_t *test_tree = NULL;
+ axis2_char_t *test_tree_str;
+ char *xml_file = "test.xml";
+ char *xpath_file = "test.xpath";
+ char *ns_file = "test.ns";
+ axiom_xpath_context_t *context = NULL;
+
+ /* Create environment */
+ axutil_env_t *env =
+ axutil_env_create_all("xpath_test.log", AXIS2_LOG_LEVEL_TRACE);
+
+ /* Set input file */
+ if (argc > 3)
+ {
+ xml_file = argv[1];
+ xpath_file = argv[2];
+ ns_file = argv[3];
+ }
+ else
+ {
+ printf("%c[%d;%dm", 27, 1, 35);
+ printf("Usage: test [xml_file xpath_file namespaces_file]\n\n");
+ printf("\tLook at the example test case:");
+ printf(" test.xml, test.xpath test.ns\n\n");
+ printf("%c[%dm", 27, 0);
+ }
+
+ /*Create the request */
+ /* test_tree = build_test_xml(env); */
+ test_tree = read_test_xml(env, (axis2_char_t *)xml_file);
+
+ if (test_tree)
+ {
+ test_tree_str = axiom_node_to_string(test_tree, env);
+ printf("%c[%d;%dm", 27, 1, 34);
+ printf("\nTesting XML\n-----------\n\"%s\"\n\n\n", test_tree_str);
+ printf("%c[%dm", 27, 0);
+
+ /* Create XPath Context */
+ context = axiom_xpath_context_create(env, test_tree);
+
+ /* Namespaces */
+ add_namespaces(env, context, ns_file);
+
+ evaluate_expressions(env, context, xpath_file);
+
+ test_tree_str = axiom_node_to_string(test_tree, env);
+ printf("%c[%d;%dm", 27, 1, 34);
+ printf("\n\nFinal XML\n-----------\n\"%s\"\n\n\n", test_tree_str);
+ printf("%c[%dm", 27, 0);
+ }
+
+ /* Freeing memory */
+ if (context)
+ {
+ axiom_xpath_free_context(env, context);
+ }
+
+ if (test_tree)
+ {
+ axiom_node_free_tree(test_tree, env);
+ }
+
+ if (env)
+ {
+ axutil_env_free((axutil_env_t *) env);
+ }
+
+ printf("%c[%d;%dm", 27, 1, 33);
+ printf("Press enter to continue...\n");
+ printf("%c[%dm", 27, 0);
+ getchar();
+
+ return 0;
+}
+
+int readline(FILE *fin, char *str)
+{
+ int i;
+
+ for (i = 0; 1; i++)
+ {
+ str[i] = (char)getc(fin);
+
+ if (str[i] == '\n' || str[i] == '\r' || str[i] == EOF)
+ {
+ break;
+ }
+ }
+
+ str[i] = '\0';
+
+ return i;
+}
+
+void add_namespaces(const axutil_env_t *env,
+ axiom_xpath_context_t *context,
+ char *file_name)
+{
+ FILE *fin = NULL;
+ char prefix[1024];
+ char uri[1024];
+ axiom_namespace_t *ns;
+
+ fin = fopen(file_name, "r");
+
+ if (!fin)
+ {
+ printf("%c[%d;%dm", 27, 1, 31);
+ printf("Error opening file: %s\n", file_name);
+ printf("%c[%dm", 27, 0);
+ return;
+ }
+
+ /* Compiling XPath expression */
+ while (1)
+ {
+ if (readline(fin, prefix) == 0)
+ {
+ break;
+ }
+
+ if (readline(fin, uri) == 0)
+ {
+ break;
+ }
+
+ ns = axiom_namespace_create(
+ env, (axis2_char_t *)uri, (axis2_char_t *)prefix);
+
+ if (ns)
+ {
+ axiom_xpath_register_namespace(context, ns);
+ }
+ }
+
+ fclose(fin);
+}
+
+void evaluate_expressions(
+ const axutil_env_t *env,
+ axiom_xpath_context_t *context,
+ char *file_name)
+{
+ FILE *fin = NULL;
+ char str[1024];
+
+ fin = fopen(file_name, "r");
+
+ if (!fin)
+ {
+ printf("%c[%d;%dm", 27, 1, 31);
+ printf("Error opening file: %s\n", file_name);
+ printf("%c[%dm", 27, 0);
+ return;
+ }
+
+ /* Compiling XPath expression */
+ while (1)
+ {
+ if (readline(fin, str) == 0)
+ {
+ break;
+ }
+
+ if (str[0] == '#')
+ {
+ printf("%c[%d;%dm%s%c[%dm", 27, 1, 32, str + 1, 27, 0);
+ continue;
+ }
+ evaluate(env, context, (axis2_char_t *)str);
+
+ printf("%c[%d;%dm", 27, 1, 33);
+ printf("Press enter to continue...\n");
+ printf("%c[%dm", 27, 0);
+ getchar();
+ }
+
+ fclose(fin);
+}
+
+void evaluate(
+ const axutil_env_t *env,
+ axiom_xpath_context_t *context,
+ axis2_char_t *expr_str)
+{
+ axiom_xpath_expression_t *expr = NULL;
+ axiom_xpath_result_t *result = NULL;
+
+ printf("%c[%d;%dm", 27, 1, 36);
+ printf("\nCompiling XPath expression: \"%s\" ...\n", expr_str);
+ printf("%c[%dm", 27, 0);
+ expr = axiom_xpath_compile_expression(env, expr_str);
+
+ if (!expr)
+ {
+ printf("%c[%d;%dm", 27, 1, 31);
+ printf("Compilation error.");
+ printf("Please check the systax of the XPath query.\n");
+ printf("%c[%dm", 27, 0);
+
+ return;
+ }
+
+ /* Evaluating XPath expression */
+ printf("%c[%d;%dm", 27, 1, 36);
+ printf("\nEvaluating XPath expression: \"%s\" ...\n", expr_str);
+ printf("%c[%dm", 27, 0);
+ result = axiom_xpath_evaluate(context, expr);
+
+ if (!result)
+ {
+ printf("%c[%d;%dm", 27, 1, 31);
+ printf("An error occured while evaluating the expression.\n");
+ printf("%c[%dm", 27, 0);
+
+ axiom_xpath_free_expression(env, expr);
+
+ return;
+ }
+
+ if (result->flag == AXIOM_XPATH_ERROR_STREAMING_NOT_SUPPORTED)
+ {
+ printf("%c[%d;%dm", 27, 1, 31);
+ printf("Streaming not supported.\n");
+ printf("%c[%dm", 27, 0);
+
+ axiom_xpath_free_expression(env, expr);
+
+ return;
+ }
+
+ printf("%c[%d;%dm", 27, 1, 36);
+ printf("\nResult Set\n");
+ printf("%c[%dm", 27, 0);
+
+ output_results(env, result);
+
+ if (result)
+ {
+ axiom_xpath_free_result(env, result);
+ }
+
+ if (expr)
+ {
+ axiom_xpath_free_expression(env, expr);
+ }
+}
+
+void output_results(const axutil_env_t *env,
+ axiom_xpath_result_t *xpath_result)
+{
+ axiom_xpath_result_node_t *xpath_result_node;
+ axiom_node_t *result_node;
+ axis2_char_t *result_str;
+ axiom_element_t *ele;
+ int i;
+
+ for (i = 0; i < axutil_array_list_size(xpath_result->nodes, env); i++)
+ {
+ xpath_result_node = axutil_array_list_get(xpath_result->nodes, env, i);
+
+ if (xpath_result_node->type == AXIOM_XPATH_TYPE_NODE)
+ {
+ result_node = xpath_result_node->value;
+ ele = (axiom_element_t *)axiom_node_get_data_element(
+ result_node, env);
+
+ if (ele)
+ {
+ /* result_str = axiom_element_get_text(ele, env, result_node); */
+ result_str = axiom_node_to_string(result_node, env);
+
+ printf("\n\"%s\"\n", result_str);
+ }
+ }
+ else if (xpath_result_node->type == AXIOM_XPATH_TYPE_ATTRIBUTE)
+ {
+ result_str =
+ axiom_attribute_get_localname(xpath_result_node->value, env);
+ printf("\n%s = ", result_str);
+ result_str =
+ axiom_attribute_get_value(xpath_result_node->value, env);
+ printf("\"%s\"\n", result_str);
+ }
+ else if (xpath_result_node->type == AXIOM_XPATH_TYPE_NAMESPACE)
+ {
+ result_str =
+ axiom_namespace_get_prefix(xpath_result_node->value, env);
+ printf("\n%s = ", result_str);
+ result_str =
+ axiom_namespace_get_uri(xpath_result_node->value, env);
+ printf("\"%s\"\n", result_str);
+ }
+ else if (xpath_result_node->type == AXIOM_XPATH_TYPE_BOOLEAN)
+ {
+ printf("\n\"%s\"\n",
+ (*(axis2_bool_t *)xpath_result_node->value) ? "true" : "false");
+ }
+ else if (xpath_result_node->type == AXIOM_XPATH_TYPE_TEXT)
+ {
+ printf("\n\"%s\"\n",
+ (axis2_char_t *)xpath_result_node->value);
+ }
+ else if (xpath_result_node->type == AXIOM_XPATH_TYPE_NUMBER)
+ {
+ printf("\n\"%lf\"\n",
+ *(double *)xpath_result_node->value);
+ }
+ }
+}
+
+axiom_node_t *read_test_xml(const axutil_env_t *env, axis2_char_t *file_name)
+{
+ axiom_xml_reader_t *reader = NULL;
+ axiom_stax_builder_t *builder = NULL;
+ axiom_document_t *document = NULL;
+ axiom_node_t *root = NULL;
+ axiom_node_t *doc_root = NULL;
+
+ /* Create parser */
+ reader = axiom_xml_reader_create_for_file(env, file_name, NULL);
+
+ if (!reader)
+ {
+ printf("%c[%d;%dm", 27, 1, 31);
+ printf("Error creating pullparser");
+ printf("%c[%dm", 27, 0);
+
+ return NULL;
+ }
+
+ /* Create axiom_stax_builder */
+ builder = axiom_stax_builder_create(env, reader);
+
+ if (!builder)
+ {
+ printf("%c[%d;%dm", 27, 1, 31);
+ printf("Error creating stax builder");
+ printf("%c[%dm", 27, 0);
+
+ return NULL;
+ }
+
+ /* Create an om document */
+ document = axiom_stax_builder_get_document(builder, env);
+
+ if (!document)
+ {
+ printf("%c[%d;%dm", 27, 1, 31);
+ printf("Error creating document");
+ printf("%c[%dm", 27, 0);
+
+ return NULL;
+ }
+
+ /* Get root element */
+ root = axiom_document_get_root_element(document, env);
+ if (!root)
+ {
+ printf("%c[%d;%dm", 27, 1, 31);
+ printf("Root element null");
+ printf("%c[%dm", 27, 0);
+
+ axiom_stax_builder_free(builder, env);
+ return NULL;
+ }
+
+ while (axiom_document_build_next(document, env));
+
+ doc_root = axiom_node_create(env);
+ axiom_node_add_child(doc_root, env, root);
+
+ return doc_root;
+}
+
+axiom_node_t * build_test_xml(const axutil_env_t *env)
+{
+ axiom_node_t *main_node;
+ axiom_node_t *order_node;
+ axiom_node_t *values_node;
+ axiom_node_t *value_node;
+ axiom_node_t *grandchild;
+ axis2_char_t value_str[255];
+ axiom_element_t *order_ele;
+ axiom_element_t *values_ele;
+ axiom_element_t *value_ele;
+ axiom_element_t *grandchild_ele;
+ axiom_attribute_t *attribute;
+ int i, N = 20;
+
+ axiom_namespace_t *ns1 =
+ axiom_namespace_create(env, "http://xpath/test", "ns1");
+
+ axiom_element_create(env, NULL, "test", ns1, &main_node);
+
+ order_ele =
+ axiom_element_create(env, main_node, "node1", NULL, &order_node);
+ axiom_element_set_text(order_ele, env, "10", order_node);
+ attribute =
+ axiom_attribute_create(env, "attr1", "attribute_value_1", NULL);
+ axiom_element_add_attribute(order_ele, env, attribute, order_node);
+
+ values_ele =
+ axiom_element_create(env, main_node, "node2", NULL, &values_node);
+
+ for (i = 0 ; i < N; i++)
+ {
+ sprintf(value_str, "%ld", i + 1);
+
+ value_ele =
+ axiom_element_create(env, values_node, "child", NULL, &value_node);
+ axiom_element_set_text(value_ele, env, value_str, value_node);
+
+ grandchild_ele =
+ axiom_element_create(env, value_node, "grandchild", NULL, &grandchild);
+ axiom_element_set_text(grandchild_ele, env, value_str /*"3 rd level"*/, grandchild);
+ }
+
+ return main_node;
+}
Added: webservices/axis2/branches/c/xpath_integration/axiom/test/xpath/test_windows.c
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/xpath_integration/axiom/test/xpath/test_windows.c?rev=701901&view=auto
==============================================================================
--- webservices/axis2/branches/c/xpath_integration/axiom/test/xpath/test_windows.c (added)
+++ webservices/axis2/branches/c/xpath_integration/axiom/test/xpath/test_windows.c Sun Oct 5 16:32:41 2008
@@ -0,0 +1,440 @@
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+Compiling For Windows:
+cl.exe /nologo /D "WIN32" /D "_WINDOWS" /D "_MBCS" /I %AXIS2C_HOME%\include /c *.c
+link.exe /LIBPATH:%AXIS2C_HOME%\lib axutil.lib axiom.lib axis2_parser.lib axis2_engine.lib /OUT:test.exe *.obj
+*/
+#include <stdio.h>
+#include <axiom.h>
+#include <axis2_util.h>
+#include <axiom_soap.h>
+#include <axis2_client.h>
+
+#include "xpath.h"
+
+/* Function headers */
+axiom_node_t *build_test_xml(const axutil_env_t *env);
+
+void output_results(const axutil_env_t *env, axiom_xpath_result_t *xpath_result);
+
+axiom_node_t *read_test_xml(const axutil_env_t *env, char *file_name);
+
+void output_results(const axutil_env_t *env,
+ axiom_xpath_result_t *xpath_result);
+
+void evaluate(const axutil_env_t *env,
+ axiom_xpath_context_t *context,
+ axis2_char_t *expr_str);
+
+void evaluate_expressions(const axutil_env_t *env,
+ axiom_xpath_context_t *context,
+ char *file_name);
+
+void add_namespaces(const axutil_env_t *env,
+ axiom_xpath_context_t *context,
+ char *file_name);
+
+int readline(FILE *fin, char *str);
+
+int main(int argc, char *argv[])
+{
+ axiom_node_t *test_tree = NULL;
+ axis2_char_t *test_tree_str;
+ char *xml_file = "test.xml";
+ char *xpath_file = "test.xpath";
+ char *ns_file = "test.ns";
+ axiom_xpath_context_t *context = NULL;
+
+ /* Create environment */
+ axutil_env_t *env =
+ axutil_env_create_all("xpath_test.log", AXIS2_LOG_LEVEL_TRACE);
+
+ /* Set input file */
+ if (argc == 4)
+ {
+ xml_file = argv[1];
+ xpath_file = argv[2];
+ ns_file = argv[3];
+ }
+ else
+ {
+ printf("Usage: test [xml_file xpath_file namespaces_file]\n\n");
+ printf("\tLook at the example test cases:");
+ printf(" test.xml, test.xpath test.ns\n\n");
+ }
+
+ /*Create the request */
+ /* test_tree = build_test_xml(env); */
+ test_tree = read_test_xml(env, (axis2_char_t *)xml_file);
+
+ if (test_tree)
+ {
+ test_tree_str = axiom_node_to_string(test_tree, env);
+ printf("\nTesting XML\n-----------\n\"%s\"\n\n\n", test_tree_str);
+
+ /* Create XPath Context */
+ context = axiom_xpath_context_create(env, test_tree);
+
+ /* Namespaces */
+ add_namespaces(env, context, ns_file);
+
+ evaluate_expressions(env, context, xpath_file);
+
+ test_tree_str = axiom_node_to_string(test_tree, env);
+ printf("\n\nFinal XML\n-----------\n\"%s\"\n\n\n", test_tree_str);
+ }
+
+ /* Freeing memory */
+ if (context)
+ {
+ axiom_xpath_free_context(env, context);
+ }
+
+ if (test_tree)
+ {
+ axiom_node_free_tree(test_tree, env);
+ }
+
+ if (env)
+ {
+ axutil_env_free((axutil_env_t *) env);
+ }
+
+ printf("Press enter to continue...\n");
+ getchar();
+
+ return 0;
+}
+
+int readline(FILE *fin, char *str)
+{
+ int i;
+
+ for (i = 0; 1; i++)
+ {
+ str[i] = (char)getc(fin);
+
+ if (str[i] == '\n' || str[i] == '\r' || str[i] == EOF)
+ {
+ break;
+ }
+ }
+
+ str[i] = '\0';
+
+ return i;
+}
+
+void add_namespaces(const axutil_env_t *env,
+ axiom_xpath_context_t *context,
+ char *file_name)
+{
+ FILE *fin = NULL;
+ char prefix[1024];
+ char uri[1024];
+ axiom_namespace_t *ns;
+
+ fin = fopen(file_name, "r");
+
+ if (!fin)
+ {
+ printf("Error opening file: %s\n", file_name);
+ return;
+ }
+
+ /* Compiling XPath expression */
+ while (1)
+ {
+ if (readline(fin, prefix) == 0)
+ {
+ break;
+ }
+
+ if (readline(fin, uri) == 0)
+ {
+ break;
+ }
+
+ ns = axiom_namespace_create(
+ env, (axis2_char_t *)uri, (axis2_char_t *)prefix);
+
+ if (ns)
+ {
+ axiom_xpath_register_namespace(context, ns);
+ }
+ }
+
+ fclose(fin);
+}
+
+void evaluate_expressions(
+ const axutil_env_t *env,
+ axiom_xpath_context_t *context,
+ char *file_name)
+{
+ FILE *fin = NULL;
+ char str[1024];
+
+ fin = fopen(file_name, "r");
+
+ if (!fin)
+ {
+ printf("Error opening file: %s\n", file_name);
+ return;
+ }
+
+ /* Compiling XPath expression */
+ while (1)
+ {
+ if (readline(fin, str) == 0)
+ {
+ break;
+ }
+
+ if (str[0] == '#')
+ {
+ printf("%s\n", str + 1);
+ continue;
+ }
+ evaluate(env, context, (axis2_char_t *)str);
+
+ printf("Press enter to continue...\n");
+ getchar();
+ }
+
+ fclose(fin);
+}
+
+void evaluate(
+ const axutil_env_t *env,
+ axiom_xpath_context_t *context,
+ axis2_char_t *expr_str)
+{
+ axiom_xpath_expression_t *expr = NULL;
+ axiom_xpath_result_t *result = NULL;
+
+ printf("\nCompiling XPath expression: \"%s\" ...\n", expr_str);
+ expr = axiom_xpath_compile_expression(env, expr_str);
+
+ if (!expr)
+ {
+ printf("Compilation error.");
+ printf("Please check the systax of the XPath query.\n");
+
+ return;
+ }
+
+ /* Evaluating XPath expression */
+ printf("\nEvaluating XPath expression: \"%s\" ...\n", expr_str);
+ result = axiom_xpath_evaluate(context, expr);
+
+ if (!result)
+ {
+ printf("An error occured while evaluating the expression.\n");
+
+ axiom_xpath_free_expression(env, expr);
+
+ return;
+ }
+
+ if (result->flag == AXIOM_XPATH_ERROR_STREAMING_NOT_SUPPORTED)
+ {
+ printf("Streaming not supported.\n");
+
+ axiom_xpath_free_expression(env, expr);
+
+ return;
+ }
+
+ printf("\nResult Set\n");
+
+ output_results(env, result);
+
+ if (result)
+ {
+ axiom_xpath_free_result(env, result);
+ }
+
+ if (expr)
+ {
+ axiom_xpath_free_expression(env, expr);
+ }
+}
+
+void output_results(const axutil_env_t *env,
+ axiom_xpath_result_t *xpath_result)
+{
+ axiom_xpath_result_node_t *xpath_result_node;
+ axiom_node_t *result_node;
+ axis2_char_t *result_str;
+ axiom_element_t *ele;
+ int i;
+
+ for (i = 0; i < axutil_array_list_size(xpath_result->nodes, env); i++)
+ {
+ xpath_result_node = axutil_array_list_get(xpath_result->nodes, env, i);
+
+ if (xpath_result_node->type == AXIOM_XPATH_TYPE_NODE)
+ {
+ result_node = xpath_result_node->value;
+ ele = (axiom_element_t *)axiom_node_get_data_element(
+ result_node, env);
+
+ if (ele)
+ {
+ /* result_str = axiom_element_get_text(ele, env, result_node); */
+ result_str = axiom_node_to_string(result_node, env);
+
+ printf("\n\"%s\"\n", result_str);
+ }
+ }
+ else if (xpath_result_node->type == AXIOM_XPATH_TYPE_ATTRIBUTE)
+ {
+ result_str =
+ axiom_attribute_get_localname(xpath_result_node->value, env);
+ printf("\n%s = ", result_str);
+ result_str =
+ axiom_attribute_get_value(xpath_result_node->value, env);
+ printf("\"%s\"\n", result_str);
+ }
+ else if (xpath_result_node->type == AXIOM_XPATH_TYPE_NAMESPACE)
+ {
+ result_str =
+ axiom_namespace_get_prefix(xpath_result_node->value, env);
+ printf("\n%s = ", result_str);
+ result_str =
+ axiom_namespace_get_uri(xpath_result_node->value, env);
+ printf("\"%s\"\n", result_str);
+ }
+ else if (xpath_result_node->type == AXIOM_XPATH_TYPE_BOOLEAN)
+ {
+ printf("\n\"%s\"\n",
+ (*(axis2_bool_t *)xpath_result_node->value) ? "true" : "false");
+ }
+ else if (xpath_result_node->type == AXIOM_XPATH_TYPE_TEXT)
+ {
+ printf("\n\"%s\"\n",
+ (axis2_char_t *)xpath_result_node->value);
+ }
+ else if (xpath_result_node->type == AXIOM_XPATH_TYPE_NUMBER)
+ {
+ printf("\n\"%lf\"\n",
+ *(double *)xpath_result_node->value);
+ }
+ }
+}
+
+axiom_node_t *read_test_xml(const axutil_env_t *env, axis2_char_t *file_name)
+{
+ axiom_xml_reader_t *reader = NULL;
+ axiom_stax_builder_t *builder = NULL;
+ axiom_document_t *document = NULL;
+ axiom_node_t *root = NULL;
+ axiom_node_t *doc_root = NULL;
+
+ /* Create parser */
+ reader = axiom_xml_reader_create_for_file(env, file_name, NULL);
+
+ if (!reader)
+ {
+ printf("Error creating pullparser");
+ return NULL;
+ }
+
+ /* Create axiom_stax_builder */
+ builder = axiom_stax_builder_create(env, reader);
+
+ if (!builder)
+ {
+ printf("Error creating stax builderr");
+ return NULL;
+ }
+
+ /* Create an om document */
+ document = axiom_stax_builder_get_document(builder, env);
+
+ if (!document)
+ {
+ printf("Error creating document");
+ return NULL;
+ }
+
+ /* Get root element */
+ root = axiom_document_get_root_element(document, env);
+ if (!root)
+ {
+ printf("Root element null ");
+ axiom_stax_builder_free(builder, env);
+ return NULL;
+ }
+
+ while (axiom_document_build_next(document, env));
+
+ doc_root = axiom_node_create(env);
+ axiom_node_add_child(doc_root, env, root);
+
+ return doc_root;
+}
+
+axiom_node_t * build_test_xml(const axutil_env_t *env)
+{
+ axiom_node_t *main_node;
+ axiom_node_t *order_node;
+ axiom_node_t *values_node;
+ axiom_node_t *value_node;
+ axiom_node_t *grandchild;
+ axis2_char_t value_str[255];
+ axiom_element_t *order_ele;
+ axiom_element_t *values_ele;
+ axiom_element_t *value_ele;
+ axiom_element_t *grandchild_ele;
+ axiom_attribute_t *attribute;
+ int i, N = 20;
+
+ axiom_namespace_t *ns1 =
+ axiom_namespace_create(env, "http://xpath/test", "ns1");
+
+ axiom_element_create(env, NULL, "test", ns1, &main_node);
+
+ order_ele =
+ axiom_element_create(env, main_node, "node1", NULL, &order_node);
+ axiom_element_set_text(order_ele, env, "10", order_node);
+ attribute =
+ axiom_attribute_create(env, "attr1", "attribute_value_1", NULL);
+ axiom_element_add_attribute(order_ele, env, attribute, order_node);
+
+ values_ele =
+ axiom_element_create(env, main_node, "node2", NULL, &values_node);
+
+ for (i = 0 ; i < N; i++)
+ {
+ sprintf(value_str, "%ld", i + 1);
+
+ value_ele =
+ axiom_element_create(env, values_node, "child", NULL, &value_node);
+ axiom_element_set_text(value_ele, env, value_str, value_node);
+
+ grandchild_ele =
+ axiom_element_create(env, value_node, "grandchild", NULL, &grandchild);
+ axiom_element_set_text(grandchild_ele, env, value_str /*"3 rd level"*/, grandchild);
+ }
+
+ return main_node;
+}