Annotation of XML/xpath.h, revision 1.21
1.1 daniel 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:
1.16 daniel 15: #include <libxml/tree.h>
1.12 daniel 16:
1.11 daniel 17: #ifdef __cplusplus
1.13 daniel 18: extern "C" {
1.11 daniel 19: #endif
1.1 daniel 20:
1.15 daniel 21: typedef struct _xmlXPathContext xmlXPathContext;
22: typedef xmlXPathContext *xmlXPathContextPtr;
23: typedef struct _xmlXPathParserContext xmlXPathParserContext;
24: typedef xmlXPathParserContext *xmlXPathParserContextPtr;
1.9 daniel 25:
1.1 daniel 26: /*
27: * A node-set (an unordered collection of nodes without duplicates)
28: */
1.15 daniel 29: typedef struct _xmlNodeSet xmlNodeSet;
30: typedef xmlNodeSet *xmlNodeSetPtr;
31: struct _xmlNodeSet {
1.17 daniel 32: int nodeNr; /* number of nodes in the set */
33: int nodeMax; /* size of the array as allocated */
1.1 daniel 34: xmlNodePtr *nodeTab; /* array of nodes in no particular order */
1.15 daniel 35: };
1.1 daniel 36:
37: /*
38: * An expression is evaluated to yield an object, which
39: * has one of the following four basic types:
40: * - node-set
41: * - boolean
42: * - number
43: * - string
1.17 daniel 44: *
45: * @@ XPointer will add more types !
1.1 daniel 46: */
47:
1.18 veillard 48: typedef enum {
49: XPATH_UNDEFINED = 0,
50: XPATH_NODESET = 1,
51: XPATH_BOOLEAN = 2,
52: XPATH_NUMBER = 3,
53: XPATH_STRING = 4,
1.20 veillard 54: XPATH_POINT = 5,
55: XPATH_RANGE = 6,
1.21 ! veillard 56: XPATH_LOCATIONSET = 7,
1.20 veillard 57: XPATH_USERS = 8
1.18 veillard 58: } xmlXPathObjectType;
1.1 daniel 59:
1.15 daniel 60: typedef struct _xmlXPathObject xmlXPathObject;
61: typedef xmlXPathObject *xmlXPathObjectPtr;
62: struct _xmlXPathObject {
1.18 veillard 63: xmlXPathObjectType type;
1.1 daniel 64: xmlNodeSetPtr nodesetval;
65: int boolval;
1.6 daniel 66: double floatval;
1.10 daniel 67: xmlChar *stringval;
1.9 daniel 68: void *user;
1.20 veillard 69: int index;
70: void *user2;
71: int index2;
1.15 daniel 72: };
1.1 daniel 73:
1.9 daniel 74: /*
75: * A conversion function is associated to a type and used to cast
76: * the new type to primitive values.
77: */
78: typedef int (*xmlXPathConvertFunc) (xmlXPathObjectPtr obj, int type);
79:
80: /*
81: * Extra type: a name and a conversion function.
82: */
83:
1.15 daniel 84: typedef struct _xmlXPathType xmlXPathType;
85: typedef xmlXPathType *xmlXPathTypePtr;
86: struct _xmlXPathType {
1.10 daniel 87: const xmlChar *name; /* the type name */
1.9 daniel 88: xmlXPathConvertFunc func; /* the conversion function */
1.15 daniel 89: };
1.9 daniel 90:
91: /*
92: * Extra variable: a name and a value.
93: */
94:
1.15 daniel 95: typedef struct _xmlXPathVariable xmlXPathVariable;
96: typedef xmlXPathVariable *xmlXPathVariablePtr;
97: struct _xmlXPathVariable {
1.10 daniel 98: const xmlChar *name; /* the variable name */
1.9 daniel 99: xmlXPathObjectPtr value; /* the value */
1.15 daniel 100: };
1.9 daniel 101:
102: /*
103: * an evaluation function, the parameters are on the context stack
104: */
105:
106: typedef void (*xmlXPathEvalFunc)(xmlXPathParserContextPtr ctxt, int nargs);
107:
108: /*
109: * Extra function: a name and a evaluation function.
110: */
111:
1.15 daniel 112: typedef struct _xmlXPathFunct xmlXPathFunct;
113: typedef xmlXPathFunct *xmlXPathFuncPtr;
114: struct _xmlXPathFunct {
1.10 daniel 115: const xmlChar *name; /* the function name */
1.9 daniel 116: xmlXPathEvalFunc func; /* the evaluation function */
1.15 daniel 117: };
1.9 daniel 118:
119: /*
120: * An axis traversal function. To traverse an axis, the engine calls
121: * the first time with cur == NULL and repeat until the function returns
122: * NULL indicating the end of the axis traversal.
123: */
124:
125: typedef xmlXPathObjectPtr (*xmlXPathAxisFunc) (xmlXPathParserContextPtr ctxt,
126: xmlXPathObjectPtr cur);
127:
128: /*
129: * Extra axis: a name and an axis function.
130: */
131:
1.15 daniel 132: typedef struct _xmlXPathAxis xmlXPathAxis;
133: typedef xmlXPathAxis *xmlXPathAxisPtr;
134: struct _xmlXPathAxis {
1.10 daniel 135: const xmlChar *name; /* the axis name */
1.9 daniel 136: xmlXPathAxisFunc func; /* the search function */
1.15 daniel 137: };
1.9 daniel 138:
1.1 daniel 139: /*
140: * Expression evaluation occurs with respect to a context.
141: * he context consists of:
142: * - a node (the context node)
143: * - a node list (the context node list)
144: * - a set of variable bindings
145: * - a function library
146: * - the set of namespace declarations in scope for the expression
147: */
148:
1.15 daniel 149: struct _xmlXPathContext {
1.2 daniel 150: xmlDocPtr doc; /* The current document */
151: xmlNodePtr node; /* The current node */
1.9 daniel 152:
153: int nb_variables; /* number of defined variables */
154: int max_variables; /* max number of variables */
155: xmlXPathVariablePtr *variables; /* Array of defined variables */
156:
157: int nb_types; /* number of defined types */
158: int max_types; /* max number of types */
159: xmlXPathTypePtr *types; /* Array of defined types */
160:
161: int nb_funcs; /* number of defined funcs */
162: int max_funcs; /* max number of funcs */
163: xmlXPathFuncPtr *funcs; /* Array of defined funcs */
164:
165: int nb_axis; /* number of defined axis */
166: int max_axis; /* max number of axis */
167: xmlXPathAxisPtr *axis; /* Array of defined axis */
168:
169: /* Namespace traversal should be implemented with user */
1.8 daniel 170: xmlNsPtr *namespaces; /* The namespaces lookup */
171: int nsNr; /* the current Namespace index */
1.9 daniel 172: void *user; /* user defined extra info */
1.18 veillard 173:
174: /* extra variables */
175: int contextSize; /* the context size */
176: int proximityPosition; /* the proximity position */
1.21 ! veillard 177:
! 178: /* extra stuff for XPointer */
! 179: int xptr; /* it this an XPointer context */
! 180: xmlNodePtr here; /* for here() */
! 181: xmlNodePtr origin; /* for origin() */
1.15 daniel 182: };
1.1 daniel 183:
184: /*
185: * An XPath parser context, it contains pure parsing informations,
186: * an xmlXPathContext, and the stack of objects.
187: */
1.15 daniel 188: struct _xmlXPathParserContext {
1.10 daniel 189: const xmlChar *cur; /* the current char being parsed */
190: const xmlChar *base; /* the full expression */
1.1 daniel 191:
192: int error; /* error code */
193:
194: xmlXPathContextPtr context; /* the evaluation context */
195: xmlXPathObjectPtr value; /* the current value */
196: int valueNr; /* number of values stacked */
197: int valueMax; /* max number of values stacked */
198: xmlXPathObjectPtr *valueTab; /* stack of values */
1.15 daniel 199: };
1.1 daniel 200:
201: /*
202: * An XPath function
203: * The arguments (if any) are popped out of the context stack
204: * and the result is pushed on the stack.
205: */
206:
1.4 daniel 207: typedef void (*xmlXPathFunction) (xmlXPathParserContextPtr ctxt, int nargs);
1.1 daniel 208:
209: /************************************************************************
210: * *
211: * Public API *
212: * *
213: ************************************************************************/
214:
1.9 daniel 215: /**
216: * Registering extensions to the expression language
217: */
218: /* TODO */ int xmlXPathRegisterType (xmlXPathContextPtr ctxt,
1.10 daniel 219: const xmlChar *name,
1.9 daniel 220: xmlXPathConvertFunc f);
221: /* TODO */ int xmlXPathRegisterAxis (xmlXPathContextPtr ctxt,
1.10 daniel 222: const xmlChar *name,
1.9 daniel 223: xmlXPathAxisFunc f);
224: /* TODO */ int xmlXPathRegisterFunc (xmlXPathContextPtr ctxt,
1.10 daniel 225: const xmlChar *name,
1.9 daniel 226: xmlXPathFunction f);
227: /* TODO */ int xmlXPathRegisterVariable (xmlXPathContextPtr ctxt,
1.10 daniel 228: const xmlChar *name,
1.9 daniel 229: xmlXPathObject value);
230:
231: /**
232: * Evaluation functions.
233: */
1.21 ! veillard 234: void xmlXPathInit (void);
1.9 daniel 235: xmlXPathContextPtr xmlXPathNewContext (xmlDocPtr doc);
1.8 daniel 236: void xmlXPathFreeContext (xmlXPathContextPtr ctxt);
1.10 daniel 237: xmlXPathObjectPtr xmlXPathEval (const xmlChar *str,
1.21 ! veillard 238: xmlXPathContextPtr ctxt);
! 239: xmlXPathObjectPtr xmlXPathEvalXPtrExpr (const xmlChar *str,
1.8 daniel 240: xmlXPathContextPtr ctxt);
241: void xmlXPathFreeObject (xmlXPathObjectPtr obj);
1.10 daniel 242: xmlXPathObjectPtr xmlXPathEvalExpression (const xmlChar *str,
1.8 daniel 243: xmlXPathContextPtr ctxt);
1.14 daniel 244: xmlNodeSetPtr xmlXPathNodeSetCreate (xmlNodePtr val);
245: void xmlXPathFreeNodeSetList (xmlXPathObjectPtr obj);
246: void xmlXPathFreeNodeSet (xmlNodeSetPtr obj);
1.3 daniel 247:
1.11 daniel 248: #ifdef __cplusplus
249: }
250: #endif
1.1 daniel 251: #endif /* ! __XML_XPATH_H__ */
Webmaster