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