Eneboo - Documentación para desarrolladores
src/libdigidoc/libxml2/include/libxml/xpath.h
Ir a la documentación de este archivo.
00001 /*
00002  * Summary: XML Path Language implementation
00003  * Description: API for the XML Path Language implementation
00004  *
00005  * XML Path Language implementation
00006  * XPath is a language for addressing parts of an XML document,
00007  * designed to be used by both XSLT and XPointer
00008  *     http://www.w3.org/TR/xpath
00009  *
00010  * Implements
00011  * W3C Recommendation 16 November 1999
00012  *     http://www.w3.org/TR/1999/REC-xpath-19991116
00013  *
00014  * Copy: See Copyright for the status of this software.
00015  *
00016  * Author: Daniel Veillard
00017  */
00018 
00019 #ifndef __XML_XPATH_H__
00020 #define __XML_XPATH_H__
00021 
00022 #include <libxml/xmlversion.h>
00023 
00024 #ifdef LIBXML_XPATH_ENABLED
00025 
00026 #include <libxml/xmlerror.h>
00027 #include <libxml/tree.h>
00028 #include <libxml/hash.h>
00029 #endif /* LIBXML_XPATH_ENABLED */
00030 
00031 #if defined(LIBXML_XPATH_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED)
00032 #ifdef __cplusplus
00033 extern "C" {
00034 #endif
00035 #endif /* LIBXML_XPATH_ENABLED or LIBXML_SCHEMAS_ENABLED */
00036         
00037 #ifdef LIBXML_XPATH_ENABLED
00038 
00039 typedef struct _xmlXPathContext xmlXPathContext;
00040 typedef xmlXPathContext *xmlXPathContextPtr;
00041 typedef struct _xmlXPathParserContext xmlXPathParserContext;
00042 typedef xmlXPathParserContext *xmlXPathParserContextPtr;
00043 
00048 typedef enum {
00049     XPATH_EXPRESSION_OK = 0,
00050     XPATH_NUMBER_ERROR,
00051     XPATH_UNFINISHED_LITERAL_ERROR,
00052     XPATH_START_LITERAL_ERROR,
00053     XPATH_VARIABLE_REF_ERROR,
00054     XPATH_UNDEF_VARIABLE_ERROR,
00055     XPATH_INVALID_PREDICATE_ERROR,
00056     XPATH_EXPR_ERROR,
00057     XPATH_UNCLOSED_ERROR,
00058     XPATH_UNKNOWN_FUNC_ERROR,
00059     XPATH_INVALID_OPERAND,
00060     XPATH_INVALID_TYPE,
00061     XPATH_INVALID_ARITY,
00062     XPATH_INVALID_CTXT_SIZE,
00063     XPATH_INVALID_CTXT_POSITION,
00064     XPATH_MEMORY_ERROR,
00065     XPTR_SYNTAX_ERROR,
00066     XPTR_RESOURCE_ERROR,
00067     XPTR_SUB_RESOURCE_ERROR,
00068     XPATH_UNDEF_PREFIX_ERROR,
00069     XPATH_ENCODING_ERROR,
00070     XPATH_INVALID_CHAR_ERROR,
00071     XPATH_INVALID_CTXT
00072 } xmlXPathError;
00073 
00074 /*
00075  * A node-set (an unordered collection of nodes without duplicates).
00076  */
00077 typedef struct _xmlNodeSet xmlNodeSet;
00078 typedef xmlNodeSet *xmlNodeSetPtr;
00079 struct _xmlNodeSet {
00080     int nodeNr;                 /* number of nodes in the set */
00081     int nodeMax;                /* size of the array as allocated */
00082     xmlNodePtr *nodeTab;        /* array of nodes in no particular order */
00083     /* @@ with_ns to check wether namespace nodes should be looked at @@ */
00084 };
00085 
00086 /*
00087  * An expression is evaluated to yield an object, which
00088  * has one of the following four basic types:
00089  *   - node-set
00090  *   - boolean
00091  *   - number
00092  *   - string
00093  *
00094  * @@ XPointer will add more types !
00095  */
00096 
00097 typedef enum {
00098     XPATH_UNDEFINED = 0,
00099     XPATH_NODESET = 1,
00100     XPATH_BOOLEAN = 2,
00101     XPATH_NUMBER = 3,
00102     XPATH_STRING = 4,
00103     XPATH_POINT = 5,
00104     XPATH_RANGE = 6,
00105     XPATH_LOCATIONSET = 7,
00106     XPATH_USERS = 8,
00107     XPATH_XSLT_TREE = 9  /* An XSLT value tree, non modifiable */
00108 } xmlXPathObjectType;
00109 
00110 typedef struct _xmlXPathObject xmlXPathObject;
00111 typedef xmlXPathObject *xmlXPathObjectPtr;
00112 struct _xmlXPathObject {
00113     xmlXPathObjectType type;
00114     xmlNodeSetPtr nodesetval;
00115     int boolval;
00116     double floatval;
00117     xmlChar *stringval;
00118     void *user;
00119     int index;
00120     void *user2;
00121     int index2;
00122 };
00123 
00134 typedef int (*xmlXPathConvertFunc) (xmlXPathObjectPtr obj, int type);
00135 
00136 /*
00137  * Extra type: a name and a conversion function.
00138  */
00139 
00140 typedef struct _xmlXPathType xmlXPathType;
00141 typedef xmlXPathType *xmlXPathTypePtr;
00142 struct _xmlXPathType {
00143     const xmlChar         *name;                /* the type name */
00144     xmlXPathConvertFunc func;           /* the conversion function */
00145 };
00146 
00147 /*
00148  * Extra variable: a name and a value.
00149  */
00150 
00151 typedef struct _xmlXPathVariable xmlXPathVariable;
00152 typedef xmlXPathVariable *xmlXPathVariablePtr;
00153 struct _xmlXPathVariable {
00154     const xmlChar       *name;          /* the variable name */
00155     xmlXPathObjectPtr value;            /* the value */
00156 };
00157 
00166 typedef void (*xmlXPathEvalFunc)(xmlXPathParserContextPtr ctxt,
00167                                  int nargs);
00168 
00169 /*
00170  * Extra function: a name and a evaluation function.
00171  */
00172 
00173 typedef struct _xmlXPathFunct xmlXPathFunct;
00174 typedef xmlXPathFunct *xmlXPathFuncPtr;
00175 struct _xmlXPathFunct {
00176     const xmlChar      *name;           /* the function name */
00177     xmlXPathEvalFunc func;              /* the evaluation function */
00178 };
00179 
00192 typedef xmlXPathObjectPtr (*xmlXPathAxisFunc) (xmlXPathParserContextPtr ctxt,
00193                                  xmlXPathObjectPtr cur);
00194 
00195 /*
00196  * Extra axis: a name and an axis function.
00197  */
00198 
00199 typedef struct _xmlXPathAxis xmlXPathAxis;
00200 typedef xmlXPathAxis *xmlXPathAxisPtr;
00201 struct _xmlXPathAxis {
00202     const xmlChar      *name;           /* the axis name */
00203     xmlXPathAxisFunc func;              /* the search function */
00204 };
00205 
00216 typedef void (*xmlXPathFunction) (xmlXPathParserContextPtr ctxt, int nargs);
00217 
00218 /*
00219  * Function and Variable Lookup.
00220  */
00221 
00233 typedef xmlXPathObjectPtr (*xmlXPathVariableLookupFunc) (void *ctxt,
00234                                          const xmlChar *name,
00235                                          const xmlChar *ns_uri);
00236 
00248 typedef xmlXPathFunction (*xmlXPathFuncLookupFunc) (void *ctxt,
00249                                          const xmlChar *name,
00250                                          const xmlChar *ns_uri);
00251 
00261 #define XML_XPATH_CHECKNS (1<<0)
00262 
00267 #define XML_XPATH_NOVAR   (1<<1)
00268 
00286 struct _xmlXPathContext {
00287     xmlDocPtr doc;                      /* The current document */
00288     xmlNodePtr node;                    /* The current node */
00289 
00290     int nb_variables_unused;            /* unused (hash table) */
00291     int max_variables_unused;           /* unused (hash table) */
00292     xmlHashTablePtr varHash;            /* Hash table of defined variables */
00293 
00294     int nb_types;                       /* number of defined types */
00295     int max_types;                      /* max number of types */
00296     xmlXPathTypePtr types;              /* Array of defined types */
00297 
00298     int nb_funcs_unused;                /* unused (hash table) */
00299     int max_funcs_unused;               /* unused (hash table) */
00300     xmlHashTablePtr funcHash;           /* Hash table of defined funcs */
00301 
00302     int nb_axis;                        /* number of defined axis */
00303     int max_axis;                       /* max number of axis */
00304     xmlXPathAxisPtr axis;               /* Array of defined axis */
00305 
00306     /* the namespace nodes of the context node */
00307     xmlNsPtr *namespaces;               /* Array of namespaces */
00308     int nsNr;                           /* number of namespace in scope */
00309     void *user;                         /* function to free */
00310 
00311     /* extra variables */
00312     int contextSize;                    /* the context size */
00313     int proximityPosition;              /* the proximity position */
00314 
00315     /* extra stuff for XPointer */
00316     int xptr;                           /* is this an XPointer context? */
00317     xmlNodePtr here;                    /* for here() */
00318     xmlNodePtr origin;                  /* for origin() */
00319 
00320     /* the set of namespace declarations in scope for the expression */
00321     xmlHashTablePtr nsHash;             /* The namespaces hash table */
00322     xmlXPathVariableLookupFunc varLookupFunc;/* variable lookup func */
00323     void *varLookupData;                /* variable lookup data */
00324 
00325     /* Possibility to link in an extra item */
00326     void *extra;                        /* needed for XSLT */
00327 
00328     /* The function name and URI when calling a function */
00329     const xmlChar *function;
00330     const xmlChar *functionURI;
00331 
00332     /* function lookup function and data */
00333     xmlXPathFuncLookupFunc funcLookupFunc;/* function lookup func */
00334     void *funcLookupData;               /* function lookup data */
00335 
00336     /* temporary namespace lists kept for walking the namespace axis */
00337     xmlNsPtr *tmpNsList;                /* Array of namespaces */
00338     int tmpNsNr;                        /* number of namespaces in scope */
00339 
00340     /* error reporting mechanism */
00341     void *userData;                     /* user specific data block */
00342     xmlStructuredErrorFunc error;       /* the callback in case of errors */
00343     xmlError lastError;                 /* the last error */
00344     xmlNodePtr debugNode;               /* the source node XSLT */
00345 
00346     /* dictionary */
00347     xmlDictPtr dict;                    /* dictionary if any */
00348 
00349     int flags;                          /* flags to control compilation */
00350 
00351     /* Cache for reusal of XPath objects */
00352     void *cache;
00353 };
00354 
00355 /*
00356  * The structure of a compiled expression form is not public.
00357  */
00358 
00359 typedef struct _xmlXPathCompExpr xmlXPathCompExpr;
00360 typedef xmlXPathCompExpr *xmlXPathCompExprPtr;
00361 
00368 struct _xmlXPathParserContext {
00369     const xmlChar *cur;                 /* the current char being parsed */
00370     const xmlChar *base;                        /* the full expression */
00371 
00372     int error;                          /* error code */
00373 
00374     xmlXPathContextPtr  context;        /* the evaluation context */
00375     xmlXPathObjectPtr     value;        /* the current value */
00376     int                 valueNr;        /* number of values stacked */
00377     int                valueMax;        /* max number of values stacked */
00378     xmlXPathObjectPtr *valueTab;        /* stack of values */
00379 
00380     xmlXPathCompExprPtr comp;           /* the precompiled expression */
00381     int xptr;                           /* it this an XPointer expression */
00382     xmlNodePtr         ancestor;        /* used for walking preceding axis */
00383 };
00384 
00385 /************************************************************************
00386  *                                                                      *
00387  *                      Public API                                      *
00388  *                                                                      *
00389  ************************************************************************/
00390 
00395 XMLPUBVAR double xmlXPathNAN;
00396 XMLPUBVAR double xmlXPathPINF;
00397 XMLPUBVAR double xmlXPathNINF;
00398 
00399 /* These macros may later turn into functions */
00408 #define xmlXPathNodeSetGetLength(ns) ((ns) ? (ns)->nodeNr : 0)
00409 
00419 #define xmlXPathNodeSetItem(ns, index)                          \
00420                 ((((ns) != NULL) &&                             \
00421                   ((index) >= 0) && ((index) < (ns)->nodeNr)) ? \
00422                  (ns)->nodeTab[(index)]                         \
00423                  : NULL)
00424 
00432 #define xmlXPathNodeSetIsEmpty(ns)                                      \
00433     (((ns) == NULL) || ((ns)->nodeNr == 0) || ((ns)->nodeTab == NULL))
00434 
00435 
00436 XMLPUBFUN void XMLCALL             
00437                     xmlXPathFreeObject          (xmlXPathObjectPtr obj);
00438 XMLPUBFUN xmlNodeSetPtr XMLCALL    
00439                     xmlXPathNodeSetCreate       (xmlNodePtr val);
00440 XMLPUBFUN void XMLCALL             
00441                     xmlXPathFreeNodeSetList     (xmlXPathObjectPtr obj);
00442 XMLPUBFUN void XMLCALL             
00443                     xmlXPathFreeNodeSet         (xmlNodeSetPtr obj);
00444 XMLPUBFUN xmlXPathObjectPtr XMLCALL  
00445                     xmlXPathObjectCopy          (xmlXPathObjectPtr val);
00446 XMLPUBFUN int XMLCALL              
00447                     xmlXPathCmpNodes            (xmlNodePtr node1,
00448                                                  xmlNodePtr node2);
00452 XMLPUBFUN int XMLCALL              
00453                     xmlXPathCastNumberToBoolean (double val);
00454 XMLPUBFUN int XMLCALL              
00455                     xmlXPathCastStringToBoolean (const xmlChar * val);
00456 XMLPUBFUN int XMLCALL              
00457                     xmlXPathCastNodeSetToBoolean(xmlNodeSetPtr ns);
00458 XMLPUBFUN int XMLCALL              
00459                     xmlXPathCastToBoolean       (xmlXPathObjectPtr val);
00460 
00461 XMLPUBFUN double XMLCALL                   
00462                     xmlXPathCastBooleanToNumber (int val);
00463 XMLPUBFUN double XMLCALL                   
00464                     xmlXPathCastStringToNumber  (const xmlChar * val);
00465 XMLPUBFUN double XMLCALL                   
00466                     xmlXPathCastNodeToNumber    (xmlNodePtr node);
00467 XMLPUBFUN double XMLCALL                   
00468                     xmlXPathCastNodeSetToNumber (xmlNodeSetPtr ns);
00469 XMLPUBFUN double XMLCALL                   
00470                     xmlXPathCastToNumber        (xmlXPathObjectPtr val);
00471 
00472 XMLPUBFUN xmlChar * XMLCALL        
00473                     xmlXPathCastBooleanToString (int val);
00474 XMLPUBFUN xmlChar * XMLCALL        
00475                     xmlXPathCastNumberToString  (double val);
00476 XMLPUBFUN xmlChar * XMLCALL        
00477                     xmlXPathCastNodeToString    (xmlNodePtr node);
00478 XMLPUBFUN xmlChar * XMLCALL        
00479                     xmlXPathCastNodeSetToString (xmlNodeSetPtr ns);
00480 XMLPUBFUN xmlChar * XMLCALL        
00481                     xmlXPathCastToString        (xmlXPathObjectPtr val);
00482 
00483 XMLPUBFUN xmlXPathObjectPtr XMLCALL  
00484                     xmlXPathConvertBoolean      (xmlXPathObjectPtr val);
00485 XMLPUBFUN xmlXPathObjectPtr XMLCALL  
00486                     xmlXPathConvertNumber       (xmlXPathObjectPtr val);
00487 XMLPUBFUN xmlXPathObjectPtr XMLCALL  
00488                     xmlXPathConvertString       (xmlXPathObjectPtr val);
00489 
00493 XMLPUBFUN xmlXPathContextPtr XMLCALL 
00494                     xmlXPathNewContext          (xmlDocPtr doc);
00495 XMLPUBFUN void XMLCALL
00496                     xmlXPathFreeContext         (xmlXPathContextPtr ctxt);
00497 XMLPUBFUN int XMLCALL
00498                     xmlXPathContextSetCache(xmlXPathContextPtr ctxt,
00499                                             int active,
00500                                             int value,
00501                                             int options);
00505 XMLPUBFUN long XMLCALL               
00506                     xmlXPathOrderDocElems       (xmlDocPtr doc);
00507 XMLPUBFUN xmlXPathObjectPtr XMLCALL  
00508                     xmlXPathEval                (const xmlChar *str,
00509                                                  xmlXPathContextPtr ctx);
00510 XMLPUBFUN xmlXPathObjectPtr XMLCALL  
00511                     xmlXPathEvalExpression      (const xmlChar *str,
00512                                                  xmlXPathContextPtr ctxt);
00513 XMLPUBFUN int XMLCALL                
00514                     xmlXPathEvalPredicate       (xmlXPathContextPtr ctxt,
00515                                                  xmlXPathObjectPtr res);
00519 XMLPUBFUN xmlXPathCompExprPtr XMLCALL 
00520                     xmlXPathCompile             (const xmlChar *str);
00521 XMLPUBFUN xmlXPathCompExprPtr XMLCALL 
00522                     xmlXPathCtxtCompile         (xmlXPathContextPtr ctxt,
00523                                                  const xmlChar *str);
00524 XMLPUBFUN xmlXPathObjectPtr XMLCALL   
00525                     xmlXPathCompiledEval        (xmlXPathCompExprPtr comp,
00526                                                  xmlXPathContextPtr ctx);
00527 XMLPUBFUN int XMLCALL   
00528                     xmlXPathCompiledEvalToBoolean(xmlXPathCompExprPtr comp,
00529                                                  xmlXPathContextPtr ctxt);
00530 XMLPUBFUN void XMLCALL                
00531                     xmlXPathFreeCompExpr        (xmlXPathCompExprPtr comp);
00532 #endif /* LIBXML_XPATH_ENABLED */
00533 #if defined(LIBXML_XPATH_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED)
00534 XMLPUBFUN void XMLCALL             
00535                     xmlXPathInit                (void);
00536 XMLPUBFUN int XMLCALL
00537                 xmlXPathIsNaN   (double val);
00538 XMLPUBFUN int XMLCALL
00539                 xmlXPathIsInf   (double val);
00540 
00541 #ifdef __cplusplus
00542 }
00543 #endif
00544 
00545 #endif /* LIBXML_XPATH_ENABLED or LIBXML_SCHEMAS_ENABLED*/
00546 #endif /* ! __XML_XPATH_H__ */
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'