epoc32/include/stdapis/libxml2/libxml2_xpath.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
     1 /*
     2  * Summary: XML Path Language implementation
     3  * Description: API for the XML Path Language implementation
     4  *
     5  * XML Path Language implementation
     6  * XPath is a language for addressing parts of an XML document,
     7  * designed to be used by both XSLT and XPointer
     8  *     http://www.w3.org/TR/xpath
     9  *
    10  * Implements
    11  * W3C Recommendation 16 November 1999
    12  *     http://www.w3.org/TR/1999/REC-xpath-19991116
    13  *
    14  * Copy: See Copyright for the status of this software.
    15  *
    16  * Author: Daniel Veillard
    17  * Portion Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. 
    18  */
    19 
    20 /** @file
    21 @publishedAll
    22 @released
    23 */
    24 
    25 #ifndef XML_XPATH_H
    26 #define XML_XPATH_H
    27 
    28 #include <stdapis/libxml2/libxml2_hash.h>
    29 #include <stdapis/libxml2/libxml2_dict.h>
    30 #include <stdapis/libxml2/libxml2_xmlerror.h>
    31 
    32 #ifdef __cplusplus
    33 extern "C" {
    34 #endif
    35 
    36 
    37 typedef struct _xmlXPathContext xmlXPathContext;
    38 typedef xmlXPathContext *xmlXPathContextPtr;
    39 typedef struct _xmlXPathParserContext xmlXPathParserContext;
    40 typedef xmlXPathParserContext *xmlXPathParserContextPtr;
    41 
    42 /**
    43  * The set of XPath error codes.
    44  */
    45 typedef enum {
    46     XPATH_EXPRESSION_OK = 0,
    47     XPATH_NUMBER_ERROR,
    48     XPATH_UNFINISHED_LITERAL_ERROR,
    49     XPATH_START_LITERAL_ERROR,
    50     XPATH_VARIABLE_REF_ERROR,
    51     XPATH_UNDEF_VARIABLE_ERROR,
    52     XPATH_INVALID_PREDICATE_ERROR,
    53     XPATH_EXPR_ERROR,
    54     XPATH_UNCLOSED_ERROR,
    55     XPATH_UNKNOWN_FUNC_ERROR,
    56     XPATH_INVALID_OPERAND,
    57     XPATH_INVALID_TYPE,
    58     XPATH_INVALID_ARITY,
    59     XPATH_INVALID_CTXT_SIZE,
    60     XPATH_INVALID_CTXT_POSITION,
    61     XPATH_MEMORY_ERROR,
    62     XPTR_SYNTAX_ERROR,
    63     XPTR_RESOURCE_ERROR,
    64     XPTR_SUB_RESOURCE_ERROR,
    65     XPATH_UNDEF_PREFIX_ERROR,
    66     XPATH_ENCODING_ERROR,
    67     XPATH_INVALID_CHAR_ERROR,
    68     XPATH_XE_EXTENSION_FUNC_ERROR
    69 } xmlXPathError;
    70 
    71 /*
    72  * A node-set (an unordered collection of nodes without duplicates).
    73  */
    74 typedef struct _xmlNodeSet xmlNodeSet;
    75 typedef xmlNodeSet *xmlNodeSetPtr;
    76 struct _xmlNodeSet {
    77     int nodeNr;             /* number of nodes in the set */
    78     int nodeMax;            /* size of the array as allocated */
    79     xmlNodePtr* nodeTab;    /* array of nodes in no particular order */
    80     /* @@ with_ns to check wether namespace nodes should be looked at @@ */
    81 };
    82 
    83 /*
    84  * An expression is evaluated to yield an object, which
    85  * has one of the following four basic types:
    86  *   - node-set
    87  *   - boolean
    88  *   - number
    89  *   - string
    90  *
    91  * @@ XPointer will add more types !
    92  */
    93 
    94 typedef enum {
    95     XPATH_UNDEFINED = 0,
    96     XPATH_NODESET = 1,
    97     XPATH_BOOLEAN = 2,
    98     XPATH_NUMBER = 3,
    99     XPATH_STRING = 4,
   100     XPATH_POINT = 5,
   101     XPATH_RANGE = 6,
   102     XPATH_LOCATIONSET = 7,
   103     XPATH_USERS = 8,
   104     XPATH_XSLT_TREE = 9  /* An XSLT value tree, non modifiable */
   105 } xmlXPathObjectType;
   106 
   107 typedef struct _xmlXPathObject xmlXPathObject;
   108 typedef xmlXPathObject *xmlXPathObjectPtr;
   109 struct _xmlXPathObject {
   110     xmlXPathObjectType  type;
   111     xmlNodeSetPtr       nodesetval;
   112     int                 boolval;
   113     double              floatval;
   114     xmlChar*            stringval;
   115     void*               user;
   116     int                 index;
   117     void*               user2;
   118     int                 index2;
   119 };
   120 
   121 /**
   122  * xmlXPathConvertFunc:
   123  * @param obj an XPath object
   124  * @param type the number of the target type
   125  *
   126  * A conversion function is associated to a type and used to cast
   127  * the new type to primitive values.
   128  *
   129  * Returns -1 in case of error, 0 otherwise
   130  */
   131 typedef int (*xmlXPathConvertFunc) (xmlXPathObjectPtr obj, int type);
   132 
   133 /*
   134  * Extra type: a name and a conversion function.
   135  */
   136 
   137 typedef struct _xmlXPathType xmlXPathType;
   138 typedef xmlXPathType *xmlXPathTypePtr;
   139 struct _xmlXPathType {
   140     const xmlChar       *name;      /* the type name */
   141     xmlXPathConvertFunc func;       /* the conversion function */
   142 };
   143 
   144 /*
   145  * Extra variable: a name and a value.
   146  */
   147 
   148 typedef struct _xmlXPathVariable xmlXPathVariable;
   149 typedef xmlXPathVariable *xmlXPathVariablePtr;
   150 struct _xmlXPathVariable {
   151     const xmlChar     *name;        /* the variable name */
   152     xmlXPathObjectPtr value;        /* the value */
   153 };
   154 
   155 /**
   156  * xmlXPathEvalFunc:
   157  * @param ctxt an XPath parser context
   158  * @param nargs the number of arguments passed to the function
   159  *
   160  * An XPath evaluation function, the parameters are on the XPath context stack.
   161  */
   162 
   163 typedef void (*xmlXPathEvalFunc)(xmlXPathParserContextPtr ctxt, int nargs);
   164 
   165 /*
   166  * Extra function: a name and a evaluation function.
   167  */
   168 
   169 typedef struct _xmlXPathFunct xmlXPathFunct;
   170 typedef xmlXPathFunct *xmlXPathFuncPtr;
   171 struct _xmlXPathFunct {
   172     const xmlChar      *name;       /* the function name */
   173     xmlXPathEvalFunc func;      /* the evaluation function */
   174 };
   175 
   176 /**
   177  * xmlXPathAxisFunc:
   178  * @param ctxt the XPath interpreter context
   179  * @param cur the previous node being explored on that axis
   180  *
   181  * An axis traversal function. To traverse an axis, the engine calls
   182  * the first time with cur == NULL and repeat until the function returns
   183  * NULL indicating the end of the axis traversal.
   184  *
   185  * Returns the next node in that axis or NULL if at the end of the axis.
   186  */
   187 
   188 typedef xmlXPathObjectPtr (*xmlXPathAxisFunc) (xmlXPathParserContextPtr ctxt, xmlXPathObjectPtr cur);
   189 
   190 /*
   191  * Extra axis: a name and an axis function.
   192  */
   193 
   194 typedef struct _xmlXPathAxis xmlXPathAxis;
   195 typedef xmlXPathAxis* xmlXPathAxisPtr;
   196 struct _xmlXPathAxis {
   197     const xmlChar*   name;       /* the axis name */
   198     xmlXPathAxisFunc func;       /* the search function */
   199 };
   200 
   201 // XMLENGINE: NEW CODE -- XForms extensions support
   202 /**
   203 Callback for resolving prefix names into namespace URIs
   204 
   205 @return Namespace URI for aNs prefix.
   206 
   207 Resolving is made with aCtxt context.
   208 
   209 This function is used internally by for implementation of
   210 namespace-resovling feature in XPath API of XML Engine
   211 (MXmlEngNamespaceResolver interface is called by libxml2)
   212 */
   213 typedef const xmlChar* (*xeXPathNsResolverFunc)(void* aCtxt, const xmlChar* aNs);
   214 //---
   215 
   216 /**
   217  * xmlXPathContext:
   218  *
   219  * Expression evaluation occurs with respect to a context.
   220  * the context consists of:
   221  *    - a node (the context node)
   222  *    - a node list (the context node list)
   223  *    - a set of variable bindings
   224  *    - a function library
   225  *    - the set of namespace declarations in scope for the expression
   226  * Following the switch to hash tables, this need to be trimmed up at
   227  * the next binary incompatible release.
   228  */
   229 struct _xmlXPathContext {
   230     xmlDocPtr doc;          /* The current document */
   231     xmlNodePtr node;            /* The current node */
   232 
   233     //int nb_variables_unused;        /* unused (hash table) */
   234     //int max_variables_unused;       /* unused (hash table) */
   235     xmlHashTablePtr varHash;        /* Hash table of defined variables */
   236 
   237     int nb_types;           /* number of defined types */
   238     int max_types;          /* max number of types */
   239     xmlXPathTypePtr types;      /* Array of defined types */
   240 
   241     //int nb_funcs_unused;        /* unused (hash table) */
   242     //int max_funcs_unused;       /* unused (hash table) */
   243     xmlHashTablePtr funcHash;       /* Hash table of defined funcs */
   244 
   245     int nb_axis;            /* number of defined axis */
   246     int max_axis;           /* max number of axis */
   247     xmlXPathAxisPtr axis;       /* Array of defined axis */
   248 
   249     /* the namespace nodes of the context node */
   250     xmlNsPtr *namespaces;       /* Array of namespaces */
   251     int nsNr;               /* number of namespace in scope */
   252     void *user;             /* function to free */
   253 
   254     /* extra variables */
   255     int contextSize;            /* the context size */
   256     int proximityPosition;      /* the proximity position */
   257 
   258     /* extra stuff for XPointer */
   259     int xptr;               /* it this an XPointer context */
   260     xmlNodePtr here;            /* for here() */
   261     xmlNodePtr origin;          /* for origin() */
   262 
   263     /* the set of namespace declarations in scope for the expression */
   264     xmlHashTablePtr nsHash;         /* The namespaces hash table */
   265     void* varLookupFunc;            /* variable lookup func */
   266     void* varLookupData;            /* variable lookup data */
   267 
   268     /* Possibility to link in an extra item */
   269     void* extra;                    /* needed for XSLT */
   270 
   271     /* The function name and URI when calling a function */
   272     const xmlChar* function;
   273     const xmlChar* functionURI;
   274 
   275     /* function lookup function and data */
   276     void* funcLookupFunc;           /* function lookup func */
   277     void* funcLookupData;           /* function lookup data */
   278 
   279     /* temporary namespace lists kept for walking the namespace axis */
   280     xmlNsPtr* tmpNsList;            /* Array of namespaces */
   281     int       tmpNsNr;              /* number of namespace in scope */
   282 
   283     /* error reporting mechanism */
   284     void*   userData;               /* user specific data block */
   285     xmlStructuredErrorFunc error;   /* the callback in case of errors */
   286     xmlError lastError;             /* the last error */
   287     xmlNodePtr debugNode;           /* the source node XSLT */
   288 
   289     /* dictionnary */
   290     xmlDictPtr dict;                /* dictionnary if any */
   291 
   292 // XMLENGINE: NEW CODE -- XForms extensions support
   293     xmlHashTablePtr instanceDocs;  /* hash table that stores instance XForms instance docs,
   294                                       not owned by the structure, will be freed by the client*/
   295     xmlNodeSetPtr   dependencyList;/* nodes that the expression depends on */
   296     xeXPathNsResolverFunc xeResolveNs; /* find namespace URI bound to prefix in the current context */
   297     void*                 xeResolveNsCtxt; /* resolver-specific context for processing */
   298 // END NEW CODE
   299 
   300 };
   301 
   302 /*
   303  * The structure of a compiled expression form has become public in XML ENGINE
   304  */
   305 
   306 typedef enum {
   307     XPATH_OP_END=0,
   308     XPATH_OP_AND,
   309     XPATH_OP_OR,
   310     XPATH_OP_EQUAL,
   311     XPATH_OP_CMP,
   312     XPATH_OP_PLUS,
   313     XPATH_OP_MULT,
   314     XPATH_OP_UNION,
   315     XPATH_OP_ROOT,
   316     XPATH_OP_NODE,
   317     XPATH_OP_RESET,
   318     XPATH_OP_COLLECT,
   319     XPATH_OP_VALUE,
   320     XPATH_OP_VARIABLE,
   321     XPATH_OP_FUNCTION,
   322     XPATH_OP_ARG,
   323     XPATH_OP_PREDICATE,
   324     XPATH_OP_FILTER,
   325     XPATH_OP_SORT
   326 #ifdef LIBXML_XPTR_ENABLED
   327     ,XPATH_OP_RANGETO
   328 #endif
   329 } xmlXPathOp;
   330 
   331 typedef struct _xmlXPathStepOp xmlXPathStepOp;
   332 typedef xmlXPathStepOp *xmlXPathStepOpPtr;
   333 struct _xmlXPathStepOp {
   334     xmlXPathOp  op;      /* The identifier of the operation */
   335     int        ch1;      /* First child */
   336     int        ch2;      /* Second child */
   337     int      value;
   338     int     value2;
   339     int     value3;
   340     void*   value4;
   341     void*   value5;
   342     void*    cache;
   343     void* cacheURI;
   344 };
   345 
   346 
   347 /**
   348  The initial size of 'steps' table in the precompiled XPath exression
   349 
   350  Double-it policy for growth is used in the code
   351 */
   352 #define XPATH_STEPS_GRANULARITY 10
   353 
   354 typedef struct _xmlXPathCompExpr xmlXPathCompExpr;
   355 typedef xmlXPathCompExpr*   xmlXPathCompExprPtr;
   356 struct _xmlXPathCompExpr {
   357     int nbStep;             /* Number of steps in this expression */
   358     int maxStep;            /* Maximum number of steps allocated */
   359     xmlXPathStepOp* steps;  /* ops for computation of this expression */
   360     int last;               /* index of last step in expression */
   361     xmlChar*    expr;       /* the expression being computed */
   362     xmlDictPtr  dict;       /* the dictionnary to use if any */
   363 #ifdef DEBUG_EVAL_COUNTS
   364     int nb;
   365     xmlChar*  string;
   366 #endif
   367 //XMLENGINE: NEW CODE
   368     void* extendedContext;  /* some data set by API users and available for XPath extension functions */
   369     void* xeNsResolver;     /* default namespace resolver supplied when compiling expression */
   370 //XMLENGINE: END NEW CODE
   371 };
   372 /**
   373  * xmlXPathParserContext:
   374  *
   375  * An XPath parser context. It contains pure parsing informations,
   376  * an xmlXPathContext, and the stack of objects.
   377  */
   378 struct _xmlXPathParserContext {
   379     const xmlChar *cur;             /* the current char being parsed */
   380     const xmlChar *base;            /* the full expression */
   381 
   382     int error;                      /* error code */
   383 
   384     xmlXPathContextPtr  context;    /* the evaluation context */
   385     xmlXPathObjectPtr     value;    /* the current value */
   386     int                 valueNr;    /* number of values stacked */
   387     int                valueMax;    /* max number of values stacked */
   388     xmlXPathObjectPtr *valueTab;    /* stack of values */
   389 
   390     xmlXPathCompExprPtr comp;       /* the precompiled expression */
   391     int xptr;                       /* it this an XPointer expression */
   392     xmlNodePtr         ancestor;    /* used for walking preceding axis */
   393 };
   394 
   395 /**
   396  * xmlXPathFunction:
   397  * @param ctxt the XPath interprestation context
   398  * @param nargs the number of arguments
   399  *
   400  * An XPath function.
   401  * The arguments (if any) are popped out from the context stack
   402  * and the result is pushed on the stack.
   403  */
   404 
   405 typedef void (*xmlXPathFunction) (xmlXPathParserContextPtr ctxt, int nargs);
   406 
   407 /************************************************************************
   408  *                                                                      *
   409  *          Public API                                                  *
   410  *                                                                      *
   411  ************************************************************************/
   412 
   413 /*
   414 NOTE: Now defined as local inline functions in xpath.c
   415       It seems that no one uses them from outside..
   416      --> used by libxslt
   417 */
   418 
   419 #define xmlXPathIsNaN(val) trio_isnan(val)
   420 #define xmlXPathIsInf(val) trio_isinf(val)
   421 
   422 
   423 /* These macros may later turn into functions */
   424 /**
   425  * xmlXPathNodeSetGetLength:
   426  * @param ns a node-set
   427  *
   428  * Implements a functionality similar to the DOM NodeList.length.
   429  *
   430  * Returns the number of nodes in the node-set.
   431  */
   432 #define xmlXPathNodeSetGetLength(ns) ((ns) ? (ns)->nodeNr : 0)
   433 /**
   434  * xmlXPathNodeSetItem:
   435  * @param ns a node-set
   436  * @param index index of a node in the set
   437  *
   438  * Implements a functionality similar to the DOM NodeList.item().
   439  *
   440  * Returns the xmlNodePtr at the given index in ns or NULL if
   441  *         index is out of range (0 to length-1)
   442  */
   443 #define xmlXPathNodeSetItem(ns, index)                          \
   444         (( (ns) && ((index) >= 0) && ((index) < (ns)->nodeNr) ) \
   445         ? (ns)->nodeTab[(index)]                                \
   446         : NULL)
   447 /**
   448  * xmlXPathNodeSetIsEmpty:
   449  * @param ns a node-set
   450  *
   451  * Checks whether ns is empty or not.
   452  *
   453  * Returns %TRUE if ns is an empty node-set.
   454  */
   455 #define xmlXPathNodeSetIsEmpty(ns)                                      \
   456     (((ns) == NULL) || ((ns)->nodeNr == 0) || ((ns)->nodeTab == NULL))
   457 
   458 
   459 XMLPUBFUN void XMLCALL
   460             xmlXPathFreeObject      (xmlXPathObjectPtr obj);
   461 XMLPUBFUN xmlNodeSetPtr XMLCALL
   462             xmlXPathNodeSetCreate   (xmlNodePtr val);
   463 XMLPUBFUN void XMLCALL
   464             xmlXPathFreeNodeSetList (xmlXPathObjectPtr obj);
   465 XMLPUBFUN void XMLCALL
   466             xmlXPathFreeNodeSet     (xmlNodeSetPtr obj);
   467 XMLPUBFUN xmlXPathObjectPtr XMLCALL
   468             xmlXPathObjectCopy      (xmlXPathObjectPtr val);
   469 XMLPUBFUN int XMLCALL
   470             xmlXPathCmpNodes        (xmlNodePtr node1, xmlNodePtr node2);
   471 /**
   472  * Conversion functions to basic types.
   473  */
   474 XMLPUBFUN int XMLCALL
   475             xmlXPathCastNumberToBoolean (double val);
   476 XMLPUBFUN int XMLCALL
   477             xmlXPathCastStringToBoolean (const xmlChar * val);
   478 XMLPUBFUN int XMLCALL
   479             xmlXPathCastNodeSetToBoolean(xmlNodeSetPtr ns);
   480 XMLPUBFUN int XMLCALL
   481             xmlXPathCastToBoolean   (xmlXPathObjectPtr val);
   482 
   483 XMLPUBFUN double XMLCALL
   484             xmlXPathCastBooleanToNumber (int val);
   485 XMLPUBFUN double XMLCALL
   486             xmlXPathCastStringToNumber  (const xmlChar * val);
   487 XMLPUBFUN double XMLCALL
   488             xmlXPathCastNodeToNumber    (xmlNodePtr node);
   489 XMLPUBFUN double XMLCALL
   490             xmlXPathCastNodeSetToNumber (xmlNodeSetPtr ns);
   491 XMLPUBFUN double XMLCALL
   492             xmlXPathCastToNumber    (xmlXPathObjectPtr val);
   493 
   494 XMLPUBFUN xmlChar* XMLCALL
   495             xmlXPathCastBooleanToString (int val);
   496 XMLPUBFUN xmlChar* XMLCALL
   497             xmlXPathCastNumberToString  (double val);
   498 XMLPUBFUN xmlChar* XMLCALL
   499             xmlXPathCastNodeToString    (xmlNodePtr node);
   500 XMLPUBFUN xmlChar* XMLCALL
   501             xmlXPathCastNodeSetToString (xmlNodeSetPtr ns);
   502 XMLPUBFUN xmlChar* XMLCALL
   503             xmlXPathCastToString    (xmlXPathObjectPtr val);
   504 
   505 XMLPUBFUN xmlXPathObjectPtr XMLCALL
   506             xmlXPathConvertBoolean  (xmlXPathObjectPtr val);
   507 XMLPUBFUN xmlXPathObjectPtr XMLCALL
   508             xmlXPathConvertNumber   (xmlXPathObjectPtr val);
   509 XMLPUBFUN xmlXPathObjectPtr XMLCALL
   510             xmlXPathConvertString   (xmlXPathObjectPtr val);
   511 
   512 /**
   513  * Context handling.
   514  */
   515 XMLPUBFUN void XMLCALL
   516             xmlXPathInit            (void);
   517 XMLPUBFUN xmlXPathContextPtr XMLCALL
   518             xmlXPathNewContext      (xmlDocPtr doc);
   519 XMLPUBFUN void XMLCALL
   520             xmlXPathFreeContext     (xmlXPathContextPtr ctxt);
   521 
   522 /**
   523  * Evaluation functions.
   524  */
   525 XMLPUBFUN long XMLCALL
   526             xmlXPathOrderDocElems   (xmlDocPtr doc);
   527 XMLPUBFUN xmlXPathObjectPtr XMLCALL
   528             xmlXPathEval            (const xmlChar *str, xmlXPathContextPtr ctx);
   529 XMLPUBFUN xmlXPathObjectPtr XMLCALL
   530             xmlXPathEvalExpression  (const xmlChar *str, xmlXPathContextPtr ctxt);
   531 XMLPUBFUN int XMLCALL
   532             xmlXPathEvalPredicate   (xmlXPathContextPtr ctxt, xmlXPathObjectPtr res);
   533 /**
   534  * Separate compilation/evaluation entry points.
   535  */
   536 XMLPUBFUN xmlXPathCompExprPtr XMLCALL
   537             xmlXPathCompile         (const xmlChar *str);
   538 XMLPUBFUN xmlXPathCompExprPtr XMLCALL
   539             xmlXPathCtxtCompile     (xmlXPathContextPtr ctxt, const xmlChar *str);
   540 XMLPUBFUN xmlXPathObjectPtr XMLCALL
   541             xmlXPathCompiledEval    (xmlXPathCompExprPtr comp,xmlXPathContextPtr ctx);
   542 XMLPUBFUN void XMLCALL
   543             xmlXPathFreeCompExpr    (xmlXPathCompExprPtr comp);
   544 
   545 #ifdef __cplusplus
   546 }
   547 #endif
   548 
   549 #endif /* XML_XPATH_H */
   550