Annotation of XML/xpath.h, revision 1.11

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

Webmaster