Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

xpath.h

Go to the documentation of this file.
00001 /*
00002  * xpath.c: interface for XML Path Language implementation
00003  *
00004  * Reference: W3C Working Draft 5 July 1999
00005  *            http://www.w3.org/Style/XSL/Group/1999/07/xpath-19990705.html
00006  *
00007  * See COPYRIGHT for the status of this software
00008  *
00009  * Author: daniel@veillard.com
00010  */
00011 
00012 #ifndef __XML_XPATH_H__
00013 #define __XML_XPATH_H__
00014 
00015 #include <libxml/xmlversion.h>
00016 #include <libxml/xmlerror.h>
00017 #include <libxml/tree.h>
00018 #include <libxml/hash.h>
00019 
00020 #ifdef __cplusplus
00021 extern "C" {
00022 #endif
00023 
00024 typedef struct _xmlXPathContext xmlXPathContext;
00025 typedef xmlXPathContext *xmlXPathContextPtr;
00026 typedef struct _xmlXPathParserContext xmlXPathParserContext;
00027 typedef xmlXPathParserContext *xmlXPathParserContextPtr;
00028 
00033 typedef enum {
00034     XPATH_EXPRESSION_OK = 0,
00035     XPATH_NUMBER_ERROR,
00036     XPATH_UNFINISHED_LITERAL_ERROR,
00037     XPATH_START_LITERAL_ERROR,
00038     XPATH_VARIABLE_REF_ERROR,
00039     XPATH_UNDEF_VARIABLE_ERROR,
00040     XPATH_INVALID_PREDICATE_ERROR,
00041     XPATH_EXPR_ERROR,
00042     XPATH_UNCLOSED_ERROR,
00043     XPATH_UNKNOWN_FUNC_ERROR,
00044     XPATH_INVALID_OPERAND,
00045     XPATH_INVALID_TYPE,
00046     XPATH_INVALID_ARITY,
00047     XPATH_INVALID_CTXT_SIZE,
00048     XPATH_INVALID_CTXT_POSITION,
00049     XPATH_MEMORY_ERROR,
00050     XPTR_SYNTAX_ERROR,
00051     XPTR_RESOURCE_ERROR,
00052     XPTR_SUB_RESOURCE_ERROR,
00053     XPATH_UNDEF_PREFIX_ERROR,
00054     XPATH_ENCODING_ERROR,
00055     XPATH_INVALID_CHAR_ERROR
00056 } xmlXPathError;
00057 
00058 /*
00059  * A node-set (an unordered collection of nodes without duplicates).
00060  */
00061 typedef struct _xmlNodeSet xmlNodeSet;
00062 typedef xmlNodeSet *xmlNodeSetPtr;
00063 struct _xmlNodeSet {
00064     int nodeNr;                 /* number of nodes in the set */
00065     int nodeMax;                /* size of the array as allocated */
00066     xmlNodePtr *nodeTab;        /* array of nodes in no particular order */
00067     /* @@ with_ns to check wether namespace nodes should be looked at @@ */
00068 };
00069 
00070 /*
00071  * An expression is evaluated to yield an object, which
00072  * has one of the following four basic types:
00073  *   - node-set
00074  *   - boolean
00075  *   - number
00076  *   - string
00077  *
00078  * @@ XPointer will add more types !
00079  */
00080 
00081 typedef enum {
00082     XPATH_UNDEFINED = 0,
00083     XPATH_NODESET = 1,
00084     XPATH_BOOLEAN = 2,
00085     XPATH_NUMBER = 3,
00086     XPATH_STRING = 4,
00087     XPATH_POINT = 5,
00088     XPATH_RANGE = 6,
00089     XPATH_LOCATIONSET = 7,
00090     XPATH_USERS = 8,
00091     XPATH_XSLT_TREE = 9  /* An XSLT value tree, non modifiable */
00092 } xmlXPathObjectType;
00093 
00094 typedef struct _xmlXPathObject xmlXPathObject;
00095 typedef xmlXPathObject *xmlXPathObjectPtr;
00096 struct _xmlXPathObject {
00097     xmlXPathObjectType type;
00098     xmlNodeSetPtr nodesetval;
00099     int boolval;
00100     double floatval;
00101     xmlChar *stringval;
00102     void *user;
00103     int index;
00104     void *user2;
00105     int index2;
00106 };
00107 
00118 typedef int (*xmlXPathConvertFunc) (xmlXPathObjectPtr obj, int type);
00119 
00120 /*
00121  * Extra type: a name and a conversion function.
00122  */
00123 
00124 typedef struct _xmlXPathType xmlXPathType;
00125 typedef xmlXPathType *xmlXPathTypePtr;
00126 struct _xmlXPathType {
00127     const xmlChar         *name;                /* the type name */
00128     xmlXPathConvertFunc func;           /* the conversion function */
00129 };
00130 
00131 /*
00132  * Extra variable: a name and a value.
00133  */
00134 
00135 typedef struct _xmlXPathVariable xmlXPathVariable;
00136 typedef xmlXPathVariable *xmlXPathVariablePtr;
00137 struct _xmlXPathVariable {
00138     const xmlChar       *name;          /* the variable name */
00139     xmlXPathObjectPtr value;            /* the value */
00140 };
00141 
00150 typedef void (*xmlXPathEvalFunc)(xmlXPathParserContextPtr ctxt,
00151                                  int nargs);
00152 
00153 /*
00154  * Extra function: a name and a evaluation function.
00155  */
00156 
00157 typedef struct _xmlXPathFunct xmlXPathFunct;
00158 typedef xmlXPathFunct *xmlXPathFuncPtr;
00159 struct _xmlXPathFunct {
00160     const xmlChar      *name;           /* the function name */
00161     xmlXPathEvalFunc func;              /* the evaluation function */
00162 };
00163 
00176 typedef xmlXPathObjectPtr (*xmlXPathAxisFunc) (xmlXPathParserContextPtr ctxt,
00177                                  xmlXPathObjectPtr cur);
00178 
00179 /*
00180  * Extra axis: a name and an axis function.
00181  */
00182 
00183 typedef struct _xmlXPathAxis xmlXPathAxis;
00184 typedef xmlXPathAxis *xmlXPathAxisPtr;
00185 struct _xmlXPathAxis {
00186     const xmlChar      *name;           /* the axis name */
00187     xmlXPathAxisFunc func;              /* the search function */
00188 };
00189 
00204 struct _xmlXPathContext {
00205     xmlDocPtr doc;                      /* The current document */
00206     xmlNodePtr node;                    /* The current node */
00207 
00208     int nb_variables_unused;            /* unused (hash table) */
00209     int max_variables_unused;           /* unused (hash table) */
00210     xmlHashTablePtr varHash;            /* Hash table of defined variables */
00211 
00212     int nb_types;                       /* number of defined types */
00213     int max_types;                      /* max number of types */
00214     xmlXPathTypePtr types;              /* Array of defined types */
00215 
00216     int nb_funcs_unused;                /* unused (hash table) */
00217     int max_funcs_unused;               /* unused (hash table) */
00218     xmlHashTablePtr funcHash;           /* Hash table of defined funcs */
00219 
00220     int nb_axis;                        /* number of defined axis */
00221     int max_axis;                       /* max number of axis */
00222     xmlXPathAxisPtr axis;               /* Array of defined axis */
00223 
00224     /* the namespace nodes of the context node */
00225     xmlNsPtr *namespaces;               /* Array of namespaces */
00226     int nsNr;                           /* number of namespace in scope */
00227     void *user;                         /* function to free */
00228 
00229     /* extra variables */
00230     int contextSize;                    /* the context size */
00231     int proximityPosition;              /* the proximity position */
00232 
00233     /* extra stuff for XPointer */
00234     int xptr;                           /* it this an XPointer context */
00235     xmlNodePtr here;                    /* for here() */
00236     xmlNodePtr origin;                  /* for origin() */
00237 
00238     /* the set of namespace declarations in scope for the expression */
00239     xmlHashTablePtr nsHash;             /* The namespaces hash table */
00240     void *varLookupFunc;                /* variable lookup func */
00241     void *varLookupData;                /* variable lookup data */
00242 
00243     /* Possibility to link in an extra item */
00244     void *extra;                        /* needed for XSLT */
00245 
00246     /* The function name and URI when calling a function */
00247     const xmlChar *function;
00248     const xmlChar *functionURI;
00249 
00250     /* function lookup function and data */
00251     void *funcLookupFunc;               /* function lookup func */
00252     void *funcLookupData;               /* function lookup data */
00253 
00254     /* temporary namespace lists kept for walking the namespace axis */
00255     xmlNsPtr *tmpNsList;                /* Array of namespaces */
00256     int tmpNsNr;                        /* number of namespace in scope */
00257 
00258     /* error reporting mechanism */
00259     void *userData;                     /* user specific data block */
00260     xmlStructuredErrorFunc error;       /* the callback in case of errors */
00261     xmlError lastError;                 /* the last error */
00262     xmlNodePtr debugNode;               /* the source node XSLT */
00263 };
00264 
00265 /*
00266  * The structure of a compiled expression form is not public.
00267  */
00268 
00269 typedef struct _xmlXPathCompExpr xmlXPathCompExpr;
00270 typedef xmlXPathCompExpr *xmlXPathCompExprPtr;
00271 
00278 struct _xmlXPathParserContext {
00279     const xmlChar *cur;                 /* the current char being parsed */
00280     const xmlChar *base;                        /* the full expression */
00281 
00282     int error;                          /* error code */
00283 
00284     xmlXPathContextPtr  context;        /* the evaluation context */
00285     xmlXPathObjectPtr     value;        /* the current value */
00286     int                 valueNr;        /* number of values stacked */
00287     int                valueMax;        /* max number of values stacked */
00288     xmlXPathObjectPtr *valueTab;        /* stack of values */
00289 
00290     xmlXPathCompExprPtr comp;           /* the precompiled expression */
00291     int xptr;                           /* it this an XPointer expression */
00292     xmlNodePtr         ancestor;        /* used for walking preceding axis */
00293 };
00294 
00305 typedef void (*xmlXPathFunction) (xmlXPathParserContextPtr ctxt, int nargs);
00306 
00307 /************************************************************************
00308  *                                                                      *
00309  *                      Public API                                      *
00310  *                                                                      *
00311  ************************************************************************/
00312 
00317 XMLPUBVAR double xmlXPathNAN;
00318 XMLPUBVAR double xmlXPathPINF;
00319 XMLPUBVAR double xmlXPathNINF;
00320 
00321 XMLPUBFUN int XMLCALL
00322                 xmlXPathIsNaN   (double val);
00323 XMLPUBFUN int XMLCALL
00324                 xmlXPathIsInf   (double val);
00325 
00326 /* These macros may later turn into functions */
00335 #define xmlXPathNodeSetGetLength(ns) ((ns) ? (ns)->nodeNr : 0)
00336 
00346 #define xmlXPathNodeSetItem(ns, index)                          \
00347                 ((((ns) != NULL) &&                             \
00348                   ((index) >= 0) && ((index) < (ns)->nodeNr)) ? \
00349                  (ns)->nodeTab[(index)]                         \
00350                  : NULL)
00351 
00359 #define xmlXPathNodeSetIsEmpty(ns)                                      \
00360     (((ns) == NULL) || ((ns)->nodeNr == 0) || ((ns)->nodeTab == NULL))
00361 
00362 
00363 XMLPUBFUN void XMLCALL             
00364                     xmlXPathFreeObject          (xmlXPathObjectPtr obj);
00365 XMLPUBFUN xmlNodeSetPtr XMLCALL    
00366                     xmlXPathNodeSetCreate       (xmlNodePtr val);
00367 XMLPUBFUN void XMLCALL             
00368                     xmlXPathFreeNodeSetList     (xmlXPathObjectPtr obj);
00369 XMLPUBFUN void XMLCALL             
00370                     xmlXPathFreeNodeSet         (xmlNodeSetPtr obj);
00371 XMLPUBFUN xmlXPathObjectPtr XMLCALL  
00372                     xmlXPathObjectCopy          (xmlXPathObjectPtr val);
00373 XMLPUBFUN int XMLCALL              
00374                     xmlXPathCmpNodes            (xmlNodePtr node1,
00375                                                  xmlNodePtr node2);
00379 XMLPUBFUN int XMLCALL              
00380                     xmlXPathCastNumberToBoolean (double val);
00381 XMLPUBFUN int XMLCALL              
00382                     xmlXPathCastStringToBoolean (const xmlChar * val);
00383 XMLPUBFUN int XMLCALL              
00384                     xmlXPathCastNodeSetToBoolean(xmlNodeSetPtr ns);
00385 XMLPUBFUN int XMLCALL              
00386                     xmlXPathCastToBoolean       (xmlXPathObjectPtr val);
00387 
00388 XMLPUBFUN double XMLCALL                   
00389                     xmlXPathCastBooleanToNumber (int val);
00390 XMLPUBFUN double XMLCALL                   
00391                     xmlXPathCastStringToNumber  (const xmlChar * val);
00392 XMLPUBFUN double XMLCALL                   
00393                     xmlXPathCastNodeToNumber    (xmlNodePtr node);
00394 XMLPUBFUN double XMLCALL                   
00395                     xmlXPathCastNodeSetToNumber (xmlNodeSetPtr ns);
00396 XMLPUBFUN double XMLCALL                   
00397                     xmlXPathCastToNumber        (xmlXPathObjectPtr val);
00398 
00399 XMLPUBFUN xmlChar * XMLCALL        
00400                     xmlXPathCastBooleanToString (int val);
00401 XMLPUBFUN xmlChar * XMLCALL        
00402                     xmlXPathCastNumberToString  (double val);
00403 XMLPUBFUN xmlChar * XMLCALL        
00404                     xmlXPathCastNodeToString    (xmlNodePtr node);
00405 XMLPUBFUN xmlChar * XMLCALL        
00406                     xmlXPathCastNodeSetToString (xmlNodeSetPtr ns);
00407 XMLPUBFUN xmlChar * XMLCALL        
00408                     xmlXPathCastToString        (xmlXPathObjectPtr val);
00409 
00410 XMLPUBFUN xmlXPathObjectPtr XMLCALL  
00411                     xmlXPathConvertBoolean      (xmlXPathObjectPtr val);
00412 XMLPUBFUN xmlXPathObjectPtr XMLCALL  
00413                     xmlXPathConvertNumber       (xmlXPathObjectPtr val);
00414 XMLPUBFUN xmlXPathObjectPtr XMLCALL  
00415                     xmlXPathConvertString       (xmlXPathObjectPtr val);
00416 
00420 XMLPUBFUN void XMLCALL             
00421                     xmlXPathInit                (void);
00422 XMLPUBFUN xmlXPathContextPtr XMLCALL 
00423                     xmlXPathNewContext          (xmlDocPtr doc);
00424 XMLPUBFUN void XMLCALL             
00425                     xmlXPathFreeContext         (xmlXPathContextPtr ctxt);
00426 
00430 XMLPUBFUN long XMLCALL               
00431                     xmlXPathOrderDocElems       (xmlDocPtr doc);
00432 XMLPUBFUN xmlXPathObjectPtr XMLCALL  
00433                     xmlXPathEval                (const xmlChar *str,
00434                                                  xmlXPathContextPtr ctx);
00435 XMLPUBFUN xmlXPathObjectPtr XMLCALL  
00436                     xmlXPathEvalExpression      (const xmlChar *str,
00437                                                  xmlXPathContextPtr ctxt);
00438 XMLPUBFUN int XMLCALL                
00439                     xmlXPathEvalPredicate       (xmlXPathContextPtr ctxt,
00440                                                  xmlXPathObjectPtr res);
00444 XMLPUBFUN xmlXPathCompExprPtr XMLCALL 
00445                     xmlXPathCompile             (const xmlChar *str);
00446 XMLPUBFUN xmlXPathObjectPtr XMLCALL   
00447                     xmlXPathCompiledEval        (xmlXPathCompExprPtr comp,
00448                                                  xmlXPathContextPtr ctx);
00449 XMLPUBFUN void XMLCALL                
00450                     xmlXPathFreeCompExpr        (xmlXPathCompExprPtr comp);
00451 #ifdef __cplusplus
00452 }
00453 #endif
00454 #endif /* ! __XML_XPATH_H__ */
00455 

Generated on Wed Mar 16 00:10:27 2005 for Dibbler - a portable DHCPv6 by  doxygen 1.3.9.1