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