xpath.h revision dbfd641b78b5a98e790459e13d126e2784a7adeb
1/* 2 * xpath.c: interface for XML Path Language implementation 3 * 4 * Reference: W3C Working Draft 5 July 1999 5 * http://www.w3.org/Style/XSL/Group/1999/07/xpath-19990705.html 6 * 7 * See COPYRIGHT for the status of this software 8 * 9 * Author: Daniel.Veillard@w3.org 10 */ 11 12#ifndef __XML_XPATH_H__ 13#define __XML_XPATH_H__ 14 15#include "tree.h" 16 17#ifdef __cplusplus 18extern "C" { 19#endif 20 21typedef struct xmlXPathParserContext *xmlXPathParserContextPtr; 22 23/* 24 * A node-set (an unordered collection of nodes without duplicates) 25 */ 26typedef struct xmlNodeSet { 27 int nodeNr; /* # of node in the set */ 28 int nodeMax; /* allocated space */ 29 xmlNodePtr *nodeTab; /* array of nodes in no particular order */ 30} xmlNodeSet, *xmlNodeSetPtr; 31 32/* 33 * An expression is evaluated to yield an object, which 34 * has one of the following four basic types: 35 * - node-set 36 * - boolean 37 * - number 38 * - string 39 */ 40 41#define XPATH_UNDEFINED 0 42#define XPATH_NODESET 1 43#define XPATH_BOOLEAN 2 44#define XPATH_NUMBER 3 45#define XPATH_STRING 4 46#define XPATH_USERS 5 47 48typedef struct xmlXPathObject { 49 int type; 50 xmlNodeSetPtr nodesetval; 51 int boolval; 52 double floatval; 53 xmlChar *stringval; 54 void *user; 55} xmlXPathObject, *xmlXPathObjectPtr; 56 57/* 58 * A conversion function is associated to a type and used to cast 59 * the new type to primitive values. 60 */ 61typedef int (*xmlXPathConvertFunc) (xmlXPathObjectPtr obj, int type); 62 63/* 64 * Extra type: a name and a conversion function. 65 */ 66 67typedef struct xmlXPathType { 68 const xmlChar *name; /* the type name */ 69 xmlXPathConvertFunc func; /* the conversion function */ 70} xmlXPathType, *xmlXPathTypePtr; 71 72/* 73 * Extra variable: a name and a value. 74 */ 75 76typedef struct xmlXPathVariable { 77 const xmlChar *name; /* the variable name */ 78 xmlXPathObjectPtr value; /* the value */ 79} xmlXPathVariable, *xmlXPathVariablePtr; 80 81/* 82 * an evaluation function, the parameters are on the context stack 83 */ 84 85typedef void (*xmlXPathEvalFunc)(xmlXPathParserContextPtr ctxt, int nargs); 86 87/* 88 * Extra function: a name and a evaluation function. 89 */ 90 91typedef struct xmlXPathFunct { 92 const xmlChar *name; /* the function name */ 93 xmlXPathEvalFunc func; /* the evaluation function */ 94} xmlXPathFunc, *xmlXPathFuncPtr; 95 96/* 97 * An axis traversal function. To traverse an axis, the engine calls 98 * the first time with cur == NULL and repeat until the function returns 99 * NULL indicating the end of the axis traversal. 100 */ 101 102typedef xmlXPathObjectPtr (*xmlXPathAxisFunc) (xmlXPathParserContextPtr ctxt, 103 xmlXPathObjectPtr cur); 104 105/* 106 * Extra axis: a name and an axis function. 107 */ 108 109typedef struct xmlXPathAxis { 110 const xmlChar *name; /* the axis name */ 111 xmlXPathAxisFunc func; /* the search function */ 112} xmlXPathAxis, *xmlXPathAxisPtr; 113 114/* 115 * Expression evaluation occurs with respect to a context. 116 * he context consists of: 117 * - a node (the context node) 118 * - a node list (the context node list) 119 * - a set of variable bindings 120 * - a function library 121 * - the set of namespace declarations in scope for the expression 122 */ 123 124typedef struct xmlXPathContext { 125 xmlDocPtr doc; /* The current document */ 126 xmlNodePtr node; /* The current node */ 127 xmlNodeSetPtr nodelist; /* The current node list */ 128 129 int nb_variables; /* number of defined variables */ 130 int max_variables; /* max number of variables */ 131 xmlXPathVariablePtr *variables; /* Array of defined variables */ 132 133 int nb_types; /* number of defined types */ 134 int max_types; /* max number of types */ 135 xmlXPathTypePtr *types; /* Array of defined types */ 136 137 int nb_funcs; /* number of defined funcs */ 138 int max_funcs; /* max number of funcs */ 139 xmlXPathFuncPtr *funcs; /* Array of defined funcs */ 140 141 int nb_axis; /* number of defined axis */ 142 int max_axis; /* max number of axis */ 143 xmlXPathAxisPtr *axis; /* Array of defined axis */ 144 145 /* Namespace traversal should be implemented with user */ 146 xmlNsPtr *namespaces; /* The namespaces lookup */ 147 int nsNr; /* the current Namespace index */ 148 void *user; /* user defined extra info */ 149} xmlXPathContext, *xmlXPathContextPtr; 150 151/* 152 * An XPath parser context, it contains pure parsing informations, 153 * an xmlXPathContext, and the stack of objects. 154 */ 155typedef struct xmlXPathParserContext { 156 const xmlChar *cur; /* the current char being parsed */ 157 const xmlChar *base; /* the full expression */ 158 159 int error; /* error code */ 160 161 xmlXPathContextPtr context; /* the evaluation context */ 162 xmlXPathObjectPtr value; /* the current value */ 163 int valueNr; /* number of values stacked */ 164 int valueMax; /* max number of values stacked */ 165 xmlXPathObjectPtr *valueTab; /* stack of values */ 166} xmlXPathParserContext; 167 168/* 169 * An XPath function 170 * The arguments (if any) are popped out of the context stack 171 * and the result is pushed on the stack. 172 */ 173 174typedef void (*xmlXPathFunction) (xmlXPathParserContextPtr ctxt, int nargs); 175 176/************************************************************************ 177 * * 178 * Public API * 179 * * 180 ************************************************************************/ 181 182/** 183 * Registering extensions to the expression language 184 */ 185/* TODO */ int xmlXPathRegisterType (xmlXPathContextPtr ctxt, 186 const xmlChar *name, 187 xmlXPathConvertFunc f); 188/* TODO */ int xmlXPathRegisterAxis (xmlXPathContextPtr ctxt, 189 const xmlChar *name, 190 xmlXPathAxisFunc f); 191/* TODO */ int xmlXPathRegisterFunc (xmlXPathContextPtr ctxt, 192 const xmlChar *name, 193 xmlXPathFunction f); 194/* TODO */ int xmlXPathRegisterVariable (xmlXPathContextPtr ctxt, 195 const xmlChar *name, 196 xmlXPathObject value); 197 198/** 199 * Evaluation functions. 200 */ 201xmlXPathContextPtr xmlXPathNewContext (xmlDocPtr doc); 202void xmlXPathFreeContext (xmlXPathContextPtr ctxt); 203xmlXPathObjectPtr xmlXPathEval (const xmlChar *str, 204 xmlXPathContextPtr ctxt); 205void xmlXPathFreeObject (xmlXPathObjectPtr obj); 206xmlXPathObjectPtr xmlXPathEvalExpression (const xmlChar *str, 207 xmlXPathContextPtr ctxt); 208xmlNodeSetPtr xmlXPathNodeSetCreate (xmlNodePtr val); 209void xmlXPathFreeNodeSetList (xmlXPathObjectPtr obj); 210void xmlXPathFreeNodeSet (xmlNodeSetPtr obj); 211 212#ifdef __cplusplus 213} 214#endif 215#endif /* ! __XML_XPATH_H__ */ 216