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