xpath.h

00001 /*
00002 
00003  * Summary: XML Path Language implementation
00004 
00005  * Description: API for the XML Path Language implementation
00006 
00007  *
00008 
00009  * XML Path Language implementation
00010 
00011  * XPath is a language for addressing parts of an XML document,
00012 
00013  * designed to be used by both XSLT and XPointer
00014 
00015  *     http://www.w3.org/TR/xpath
00016 
00017  *
00018 
00019  * Implements
00020 
00021  * W3C Recommendation 16 November 1999
00022 
00023  *     http://www.w3.org/TR/1999/REC-xpath-19991116
00024 
00025  *
00026 
00027  * Copy: See Copyright for the status of this software.
00028 
00029  *
00030 
00031  * Author: Daniel Veillard
00032 
00033  */
00034 
00035 
00036 
00037 #ifndef __XML_XPATH_H__
00038 
00039 #define __XML_XPATH_H__
00040 
00041 
00042 
00043 #include <libxml/xmlversion.h>
00044 
00045 
00046 
00047 #ifdef LIBXML_XPATH_ENABLED
00048 
00049 
00050 
00051 #include <libxml/xmlerror.h>
00052 
00053 #include <libxml/tree.h>
00054 
00055 #include <libxml/hash.h>
00056 
00057 #endif /* LIBXML_XPATH_ENABLED */
00058 
00059 
00060 
00061 #if defined(LIBXML_XPATH_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED)
00062 
00063 #ifdef __cplusplus
00064 
00065 extern "C" {
00066 
00067 #endif
00068 
00069 #endif /* LIBXML_XPATH_ENABLED or LIBXML_SCHEMAS_ENABLED */
00070 
00071         
00072 
00073 #ifdef LIBXML_XPATH_ENABLED
00074 
00075 typedef struct _xmlXPathContext xmlXPathContext;
00076 
00077 typedef xmlXPathContext *xmlXPathContextPtr;
00078 
00079 typedef struct _xmlXPathParserContext xmlXPathParserContext;
00080 
00081 typedef xmlXPathParserContext *xmlXPathParserContextPtr;
00082 
00083 
00084 
00093 typedef enum {
00094 
00095     XPATH_EXPRESSION_OK = 0,
00096 
00097     XPATH_NUMBER_ERROR,
00098 
00099     XPATH_UNFINISHED_LITERAL_ERROR,
00100 
00101     XPATH_START_LITERAL_ERROR,
00102 
00103     XPATH_VARIABLE_REF_ERROR,
00104 
00105     XPATH_UNDEF_VARIABLE_ERROR,
00106 
00107     XPATH_INVALID_PREDICATE_ERROR,
00108 
00109     XPATH_EXPR_ERROR,
00110 
00111     XPATH_UNCLOSED_ERROR,
00112 
00113     XPATH_UNKNOWN_FUNC_ERROR,
00114 
00115     XPATH_INVALID_OPERAND,
00116 
00117     XPATH_INVALID_TYPE,
00118 
00119     XPATH_INVALID_ARITY,
00120 
00121     XPATH_INVALID_CTXT_SIZE,
00122 
00123     XPATH_INVALID_CTXT_POSITION,
00124 
00125     XPATH_MEMORY_ERROR,
00126 
00127     XPTR_SYNTAX_ERROR,
00128 
00129     XPTR_RESOURCE_ERROR,
00130 
00131     XPTR_SUB_RESOURCE_ERROR,
00132 
00133     XPATH_UNDEF_PREFIX_ERROR,
00134 
00135     XPATH_ENCODING_ERROR,
00136 
00137     XPATH_INVALID_CHAR_ERROR,
00138 
00139     XPATH_INVALID_CTXT
00140 
00141 } xmlXPathError;
00142 
00143 
00144 
00145 /*
00146 
00147  * A node-set (an unordered collection of nodes without duplicates).
00148 
00149  */
00150 
00151 typedef struct _xmlNodeSet xmlNodeSet;
00152 
00153 typedef xmlNodeSet *xmlNodeSetPtr;
00154 
00155 struct _xmlNodeSet {
00156 
00157     int nodeNr;                 /* number of nodes in the set */
00158 
00159     int nodeMax;                /* size of the array as allocated */
00160 
00161     xmlNodePtr *nodeTab;        /* array of nodes in no particular order */
00162 
00163     /* @@ with_ns to check wether namespace nodes should be looked at @@ */
00164 
00165 };
00166 
00167 
00168 
00169 /*
00170 
00171  * An expression is evaluated to yield an object, which
00172 
00173  * has one of the following four basic types:
00174 
00175  *   - node-set
00176 
00177  *   - boolean
00178 
00179  *   - number
00180 
00181  *   - string
00182 
00183  *
00184 
00185  * @@ XPointer will add more types !
00186 
00187  */
00188 
00189 
00190 
00191 typedef enum {
00192 
00193     XPATH_UNDEFINED = 0,
00194 
00195     XPATH_NODESET = 1,
00196 
00197     XPATH_BOOLEAN = 2,
00198 
00199     XPATH_NUMBER = 3,
00200 
00201     XPATH_STRING = 4,
00202 
00203     XPATH_POINT = 5,
00204 
00205     XPATH_RANGE = 6,
00206 
00207     XPATH_LOCATIONSET = 7,
00208 
00209     XPATH_USERS = 8,
00210 
00211     XPATH_XSLT_TREE = 9  /* An XSLT value tree, non modifiable */
00212 
00213 } xmlXPathObjectType;
00214 
00215 
00216 
00217 typedef struct _xmlXPathObject xmlXPathObject;
00218 
00219 typedef xmlXPathObject *xmlXPathObjectPtr;
00220 
00221 struct _xmlXPathObject {
00222 
00223     xmlXPathObjectType type;
00224 
00225     xmlNodeSetPtr nodesetval;
00226 
00227     int boolval;
00228 
00229     double floatval;
00230 
00231     xmlChar *stringval;
00232 
00233     void *user;
00234 
00235     int index;
00236 
00237     void *user2;
00238 
00239     int index2;
00240 
00241 };
00242 
00243 
00244 
00265 typedef int (*xmlXPathConvertFunc) (xmlXPathObjectPtr obj, int type);
00266 
00267 
00268 
00269 /*
00270 
00271  * Extra type: a name and a conversion function.
00272 
00273  */
00274 
00275 
00276 
00277 typedef struct _xmlXPathType xmlXPathType;
00278 
00279 typedef xmlXPathType *xmlXPathTypePtr;
00280 
00281 struct _xmlXPathType {
00282 
00283     const xmlChar         *name;                /* the type name */
00284 
00285     xmlXPathConvertFunc func;           /* the conversion function */
00286 
00287 };
00288 
00289 
00290 
00291 /*
00292 
00293  * Extra variable: a name and a value.
00294 
00295  */
00296 
00297 
00298 
00299 typedef struct _xmlXPathVariable xmlXPathVariable;
00300 
00301 typedef xmlXPathVariable *xmlXPathVariablePtr;
00302 
00303 struct _xmlXPathVariable {
00304 
00305     const xmlChar       *name;          /* the variable name */
00306 
00307     xmlXPathObjectPtr value;            /* the value */
00308 
00309 };
00310 
00311 
00312 
00329 typedef void (*xmlXPathEvalFunc)(xmlXPathParserContextPtr ctxt,
00330 
00331                                  int nargs);
00332 
00333 
00334 
00335 /*
00336 
00337  * Extra function: a name and a evaluation function.
00338 
00339  */
00340 
00341 
00342 
00343 typedef struct _xmlXPathFunct xmlXPathFunct;
00344 
00345 typedef xmlXPathFunct *xmlXPathFuncPtr;
00346 
00347 struct _xmlXPathFunct {
00348 
00349     const xmlChar      *name;           /* the function name */
00350 
00351     xmlXPathEvalFunc func;              /* the evaluation function */
00352 
00353 };
00354 
00355 
00356 
00381 typedef xmlXPathObjectPtr (*xmlXPathAxisFunc) (xmlXPathParserContextPtr ctxt,
00382 
00383                                  xmlXPathObjectPtr cur);
00384 
00385 
00386 
00387 /*
00388 
00389  * Extra axis: a name and an axis function.
00390 
00391  */
00392 
00393 
00394 
00395 typedef struct _xmlXPathAxis xmlXPathAxis;
00396 
00397 typedef xmlXPathAxis *xmlXPathAxisPtr;
00398 
00399 struct _xmlXPathAxis {
00400 
00401     const xmlChar      *name;           /* the axis name */
00402 
00403     xmlXPathAxisFunc func;              /* the search function */
00404 
00405 };
00406 
00407 
00408 
00429 typedef void (*xmlXPathFunction) (xmlXPathParserContextPtr ctxt, int nargs);
00430 
00431 
00432 
00433 /*
00434 
00435  * Function and Variable Lookup.
00436 
00437  */
00438 
00439 
00440 
00463 typedef xmlXPathObjectPtr (*xmlXPathVariableLookupFunc) (void *ctxt,
00464 
00465                                          const xmlChar *name,
00466 
00467                                          const xmlChar *ns_uri);
00468 
00469 
00470 
00493 typedef xmlXPathFunction (*xmlXPathFuncLookupFunc) (void *ctxt,
00494 
00495                                          const xmlChar *name,
00496 
00497                                          const xmlChar *ns_uri);
00498 
00499 
00500 
00529 struct _xmlXPathContext {
00530 
00531     xmlDocPtr doc;                      /* The current document */
00532 
00533     xmlNodePtr node;                    /* The current node */
00534 
00535 
00536 
00537     int nb_variables_unused;            /* unused (hash table) */
00538 
00539     int max_variables_unused;           /* unused (hash table) */
00540 
00541     xmlHashTablePtr varHash;            /* Hash table of defined variables */
00542 
00543 
00544 
00545     int nb_types;                       /* number of defined types */
00546 
00547     int max_types;                      /* max number of types */
00548 
00549     xmlXPathTypePtr types;              /* Array of defined types */
00550 
00551 
00552 
00553     int nb_funcs_unused;                /* unused (hash table) */
00554 
00555     int max_funcs_unused;               /* unused (hash table) */
00556 
00557     xmlHashTablePtr funcHash;           /* Hash table of defined funcs */
00558 
00559 
00560 
00561     int nb_axis;                        /* number of defined axis */
00562 
00563     int max_axis;                       /* max number of axis */
00564 
00565     xmlXPathAxisPtr axis;               /* Array of defined axis */
00566 
00567 
00568 
00569     /* the namespace nodes of the context node */
00570 
00571     xmlNsPtr *namespaces;               /* Array of namespaces */
00572 
00573     int nsNr;                           /* number of namespace in scope */
00574 
00575     void *user;                         /* function to free */
00576 
00577 
00578 
00579     /* extra variables */
00580 
00581     int contextSize;                    /* the context size */
00582 
00583     int proximityPosition;              /* the proximity position */
00584 
00585 
00586 
00587     /* extra stuff for XPointer */
00588 
00589     int xptr;                           /* it this an XPointer context */
00590 
00591     xmlNodePtr here;                    /* for here() */
00592 
00593     xmlNodePtr origin;                  /* for origin() */
00594 
00595 
00596 
00597     /* the set of namespace declarations in scope for the expression */
00598 
00599     xmlHashTablePtr nsHash;             /* The namespaces hash table */
00600 
00601     xmlXPathVariableLookupFunc varLookupFunc;/* variable lookup func */
00602 
00603     void *varLookupData;                /* variable lookup data */
00604 
00605 
00606 
00607     /* Possibility to link in an extra item */
00608 
00609     void *extra;                        /* needed for XSLT */
00610 
00611 
00612 
00613     /* The function name and URI when calling a function */
00614 
00615     const xmlChar *function;
00616 
00617     const xmlChar *functionURI;
00618 
00619 
00620 
00621     /* function lookup function and data */
00622 
00623     xmlXPathFuncLookupFunc funcLookupFunc;/* function lookup func */
00624 
00625     void *funcLookupData;               /* function lookup data */
00626 
00627 
00628 
00629     /* temporary namespace lists kept for walking the namespace axis */
00630 
00631     xmlNsPtr *tmpNsList;                /* Array of namespaces */
00632 
00633     int tmpNsNr;                        /* number of namespace in scope */
00634 
00635 
00636 
00637     /* error reporting mechanism */
00638 
00639     void *userData;                     /* user specific data block */
00640 
00641     xmlStructuredErrorFunc error;       /* the callback in case of errors */
00642 
00643     xmlError lastError;                 /* the last error */
00644 
00645     xmlNodePtr debugNode;               /* the source node XSLT */
00646 
00647 
00648 
00649     /* dictionnary */
00650 
00651     xmlDictPtr dict;                    /* dictionnary if any */
00652 
00653 };
00654 
00655 
00656 
00657 /*
00658 
00659  * The structure of a compiled expression form is not public.
00660 
00661  */
00662 
00663 
00664 
00665 typedef struct _xmlXPathCompExpr xmlXPathCompExpr;
00666 
00667 typedef xmlXPathCompExpr *xmlXPathCompExprPtr;
00668 
00669 
00670 
00683 struct _xmlXPathParserContext {
00684 
00685     const xmlChar *cur;                 /* the current char being parsed */
00686 
00687     const xmlChar *base;                        /* the full expression */
00688 
00689 
00690 
00691     int error;                          /* error code */
00692 
00693 
00694 
00695     xmlXPathContextPtr  context;        /* the evaluation context */
00696 
00697     xmlXPathObjectPtr     value;        /* the current value */
00698 
00699     int                 valueNr;        /* number of values stacked */
00700 
00701     int                valueMax;        /* max number of values stacked */
00702 
00703     xmlXPathObjectPtr *valueTab;        /* stack of values */
00704 
00705 
00706 
00707     xmlXPathCompExprPtr comp;           /* the precompiled expression */
00708 
00709     int xptr;                           /* it this an XPointer expression */
00710 
00711     xmlNodePtr         ancestor;        /* used for walking preceding axis */
00712 
00713 };
00714 
00715 
00716 
00717 /************************************************************************
00718 
00719  *                                                                      *
00720 
00721  *                      Public API                                      *
00722 
00723  *                                                                      *
00724 
00725  ************************************************************************/
00726 
00727 
00728 
00737 XMLPUBVAR double xmlXPathNAN;
00738 
00739 XMLPUBVAR double xmlXPathPINF;
00740 
00741 XMLPUBVAR double xmlXPathNINF;
00742 
00743 
00744 
00745 /* These macros may later turn into functions */
00746 
00763 #define xmlXPathNodeSetGetLength(ns) ((ns) ? (ns)->nodeNr : 0)
00764 
00785 #define xmlXPathNodeSetItem(ns, index)                          \
00786 
00787                 ((((ns) != NULL) &&                             \
00788 
00789                   ((index) >= 0) && ((index) < (ns)->nodeNr)) ? \
00790 
00791                  (ns)->nodeTab[(index)]                         \
00792 
00793                  : NULL)
00794 
00811 #define xmlXPathNodeSetIsEmpty(ns)                                      \
00812 
00813     (((ns) == NULL) || ((ns)->nodeNr == 0) || ((ns)->nodeTab == NULL))
00814 
00815 
00816 
00817 
00818 
00819 XMLPUBFUN void XMLCALL             
00820 
00821                     xmlXPathFreeObject          (xmlXPathObjectPtr obj);
00822 
00823 XMLPUBFUN xmlNodeSetPtr XMLCALL    
00824 
00825                     xmlXPathNodeSetCreate       (xmlNodePtr val);
00826 
00827 XMLPUBFUN void XMLCALL             
00828 
00829                     xmlXPathFreeNodeSetList     (xmlXPathObjectPtr obj);
00830 
00831 XMLPUBFUN void XMLCALL             
00832 
00833                     xmlXPathFreeNodeSet         (xmlNodeSetPtr obj);
00834 
00835 XMLPUBFUN xmlXPathObjectPtr XMLCALL  
00836 
00837                     xmlXPathObjectCopy          (xmlXPathObjectPtr val);
00838 
00839 XMLPUBFUN int XMLCALL              
00840 
00841                     xmlXPathCmpNodes            (xmlNodePtr node1,
00842 
00843                                                  xmlNodePtr node2);
00844 
00851 XMLPUBFUN int XMLCALL              
00852 
00853                     xmlXPathCastNumberToBoolean (double val);
00854 
00855 XMLPUBFUN int XMLCALL              
00856 
00857                     xmlXPathCastStringToBoolean (const xmlChar * val);
00858 
00859 XMLPUBFUN int XMLCALL              
00860 
00861                     xmlXPathCastNodeSetToBoolean(xmlNodeSetPtr ns);
00862 
00863 XMLPUBFUN int XMLCALL              
00864 
00865                     xmlXPathCastToBoolean       (xmlXPathObjectPtr val);
00866 
00867 
00868 
00869 XMLPUBFUN double XMLCALL                   
00870 
00871                     xmlXPathCastBooleanToNumber (int val);
00872 
00873 XMLPUBFUN double XMLCALL                   
00874 
00875                     xmlXPathCastStringToNumber  (const xmlChar * val);
00876 
00877 XMLPUBFUN double XMLCALL                   
00878 
00879                     xmlXPathCastNodeToNumber    (xmlNodePtr node);
00880 
00881 XMLPUBFUN double XMLCALL                   
00882 
00883                     xmlXPathCastNodeSetToNumber (xmlNodeSetPtr ns);
00884 
00885 XMLPUBFUN double XMLCALL                   
00886 
00887                     xmlXPathCastToNumber        (xmlXPathObjectPtr val);
00888 
00889 
00890 
00891 XMLPUBFUN xmlChar * XMLCALL        
00892 
00893                     xmlXPathCastBooleanToString (int val);
00894 
00895 XMLPUBFUN xmlChar * XMLCALL        
00896 
00897                     xmlXPathCastNumberToString  (double val);
00898 
00899 XMLPUBFUN xmlChar * XMLCALL        
00900 
00901                     xmlXPathCastNodeToString    (xmlNodePtr node);
00902 
00903 XMLPUBFUN xmlChar * XMLCALL        
00904 
00905                     xmlXPathCastNodeSetToString (xmlNodeSetPtr ns);
00906 
00907 XMLPUBFUN xmlChar * XMLCALL        
00908 
00909                     xmlXPathCastToString        (xmlXPathObjectPtr val);
00910 
00911 
00912 
00913 XMLPUBFUN xmlXPathObjectPtr XMLCALL  
00914 
00915                     xmlXPathConvertBoolean      (xmlXPathObjectPtr val);
00916 
00917 XMLPUBFUN xmlXPathObjectPtr XMLCALL  
00918 
00919                     xmlXPathConvertNumber       (xmlXPathObjectPtr val);
00920 
00921 XMLPUBFUN xmlXPathObjectPtr XMLCALL  
00922 
00923                     xmlXPathConvertString       (xmlXPathObjectPtr val);
00924 
00925 
00926 
00933 XMLPUBFUN xmlXPathContextPtr XMLCALL 
00934 
00935                     xmlXPathNewContext          (xmlDocPtr doc);
00936 
00937 XMLPUBFUN void XMLCALL             
00938 
00939                     xmlXPathFreeContext         (xmlXPathContextPtr ctxt);
00940 
00941 
00942 
00949 XMLPUBFUN long XMLCALL               
00950 
00951                     xmlXPathOrderDocElems       (xmlDocPtr doc);
00952 
00953 XMLPUBFUN xmlXPathObjectPtr XMLCALL  
00954 
00955                     xmlXPathEval                (const xmlChar *str,
00956 
00957                                                  xmlXPathContextPtr ctx);
00958 
00959 XMLPUBFUN xmlXPathObjectPtr XMLCALL  
00960 
00961                     xmlXPathEvalExpression      (const xmlChar *str,
00962 
00963                                                  xmlXPathContextPtr ctxt);
00964 
00965 XMLPUBFUN int XMLCALL                
00966 
00967                     xmlXPathEvalPredicate       (xmlXPathContextPtr ctxt,
00968 
00969                                                  xmlXPathObjectPtr res);
00970 
00977 XMLPUBFUN xmlXPathCompExprPtr XMLCALL 
00978 
00979                     xmlXPathCompile             (const xmlChar *str);
00980 
00981 XMLPUBFUN xmlXPathCompExprPtr XMLCALL 
00982 
00983                     xmlXPathCtxtCompile         (xmlXPathContextPtr ctxt,
00984 
00985                                                  const xmlChar *str);
00986 
00987 XMLPUBFUN xmlXPathObjectPtr XMLCALL   
00988 
00989                     xmlXPathCompiledEval        (xmlXPathCompExprPtr comp,
00990 
00991                                                  xmlXPathContextPtr ctx);
00992 
00993 XMLPUBFUN void XMLCALL                
00994 
00995                     xmlXPathFreeCompExpr        (xmlXPathCompExprPtr comp);
00996 
00997 #endif /* LIBXML_XPATH_ENABLED */
00998 
00999 #if defined(LIBXML_XPATH_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED)
01000 
01001 XMLPUBFUN void XMLCALL             
01002 
01003                     xmlXPathInit                (void);
01004 
01005 XMLPUBFUN int XMLCALL
01006 
01007                 xmlXPathIsNaN   (double val);
01008 
01009 XMLPUBFUN int XMLCALL
01010 
01011                 xmlXPathIsInf   (double val);
01012 
01013 
01014 
01015 #ifdef __cplusplus
01016 
01017 }
01018 
01019 #endif
01020 
01021 
01022 
01023 #endif /* LIBXML_XPATH_ENABLED or LIBXML_SCHEMAS_ENABLED*/
01024 
01025 #endif /* ! __XML_XPATH_H__ */
01026 

Generated on Wed Jul 26 13:30:47 2006 for XSB by  doxygen 1.4.5