Daniel Veillard | 1566d3a | 1999-07-15 14:24:29 +0000 | [diff] [blame] | 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 | |
| 17 | /* |
| 18 | * A node-set (an unordered collection of nodes without duplicates) |
| 19 | */ |
| 20 | typedef struct xmlNodeSet { |
| 21 | int nodeNr; /* # of node in the set */ |
| 22 | int nodeMax; /* allocated space */ |
| 23 | xmlNodePtr *nodeTab; /* array of nodes in no particular order */ |
| 24 | } xmlNodeSet, *xmlNodeSetPtr; |
| 25 | |
| 26 | /* |
| 27 | * An expression is evaluated to yield an object, which |
| 28 | * has one of the following four basic types: |
| 29 | * - node-set |
| 30 | * - boolean |
| 31 | * - number |
| 32 | * - string |
| 33 | */ |
| 34 | |
| 35 | #define XPATH_UNDEFINED 0 |
| 36 | #define XPATH_NODESET 1 |
| 37 | #define XPATH_BOOLEAN 2 |
| 38 | #define XPATH_NUMBER 3 |
| 39 | #define XPATH_STRING 4 |
Daniel Veillard | 1566d3a | 1999-07-15 14:24:29 +0000 | [diff] [blame] | 40 | |
| 41 | typedef struct xmlXPathObject { |
| 42 | int type; |
| 43 | xmlNodeSetPtr nodesetval; |
| 44 | int boolval; |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame^] | 45 | double floatval; |
Daniel Veillard | 1566d3a | 1999-07-15 14:24:29 +0000 | [diff] [blame] | 46 | CHAR *stringval; |
| 47 | } xmlXPathObject, *xmlXPathObjectPtr; |
| 48 | |
| 49 | /* |
| 50 | * Expression evaluation occurs with respect to a context. |
| 51 | * he context consists of: |
| 52 | * - a node (the context node) |
| 53 | * - a node list (the context node list) |
| 54 | * - a set of variable bindings |
| 55 | * - a function library |
| 56 | * - the set of namespace declarations in scope for the expression |
| 57 | */ |
| 58 | |
| 59 | typedef struct xmlXPathContext { |
| 60 | xmlDocPtr doc; /* The current document */ |
| 61 | xmlNodePtr node; /* The current node */ |
| 62 | xmlNodeSetPtr nodelist; /* The current node list */ |
| 63 | void *variables; /* TODO !!!! */ |
| 64 | void *functions; /* TODO !!!! */ |
| 65 | void *namespaces; /* TODO !!!! */ |
| 66 | } xmlXPathContext, *xmlXPathContextPtr; |
| 67 | |
| 68 | /* |
| 69 | * An XPath parser context, it contains pure parsing informations, |
| 70 | * an xmlXPathContext, and the stack of objects. |
| 71 | */ |
| 72 | typedef struct xmlXPathParserContext { |
| 73 | const CHAR *cur; /* the current char being parsed */ |
| 74 | const CHAR *base; /* the full expression */ |
| 75 | |
| 76 | int error; /* error code */ |
| 77 | |
| 78 | xmlXPathContextPtr context; /* the evaluation context */ |
| 79 | xmlXPathObjectPtr value; /* the current value */ |
| 80 | int valueNr; /* number of values stacked */ |
| 81 | int valueMax; /* max number of values stacked */ |
| 82 | xmlXPathObjectPtr *valueTab; /* stack of values */ |
| 83 | } xmlXPathParserContext, *xmlXPathParserContextPtr; |
| 84 | |
| 85 | /* |
| 86 | * An XPath function |
| 87 | * The arguments (if any) are popped out of the context stack |
| 88 | * and the result is pushed on the stack. |
| 89 | */ |
| 90 | |
| 91 | typedef void (*xmlXPathFunction) (xmlXPathParserContextPtr ctxt, int nargs); |
| 92 | |
| 93 | /************************************************************************ |
| 94 | * * |
| 95 | * Public API * |
| 96 | * * |
| 97 | ************************************************************************/ |
| 98 | |
| 99 | xmlXPathContextPtr xmlXPathNewContext(xmlDocPtr doc, void *variables, |
| 100 | void *functions, void *namespaces); |
| 101 | void xmlXPathFreeContext(xmlXPathContextPtr ctxt); |
| 102 | xmlXPathObjectPtr xmlXPathEval(const CHAR *str, xmlXPathContextPtr ctxt); |
| 103 | void xmlXPathFreeObject(xmlXPathObjectPtr obj); |
| 104 | xmlXPathObjectPtr xmlXPathEvalExpression(const CHAR *str, |
| 105 | xmlXPathContextPtr ctxt); |
| 106 | |
| 107 | #endif /* ! __XML_XPATH_H__ */ |