Annotation of XML/xpath.h, revision 1.12

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

Webmaster