Path: blob/master/venv/Lib/site-packages/lxml/includes/libxml/xpath.h
811 views
/*1* Summary: XML Path Language implementation2* Description: API for the XML Path Language implementation3*4* XML Path Language implementation5* XPath is a language for addressing parts of an XML document,6* designed to be used by both XSLT and XPointer7* http://www.w3.org/TR/xpath8*9* Implements10* W3C Recommendation 16 November 199911* http://www.w3.org/TR/1999/REC-xpath-1999111612*13* Copy: See Copyright for the status of this software.14*15* Author: Daniel Veillard16*/1718#ifndef __XML_XPATH_H__19#define __XML_XPATH_H__2021#include <libxml/xmlversion.h>2223#ifdef LIBXML_XPATH_ENABLED2425#include <libxml/xmlerror.h>26#include <libxml/tree.h>27#include <libxml/hash.h>28#endif /* LIBXML_XPATH_ENABLED */2930#if defined(LIBXML_XPATH_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED)31#ifdef __cplusplus32extern "C" {33#endif34#endif /* LIBXML_XPATH_ENABLED or LIBXML_SCHEMAS_ENABLED */3536#ifdef LIBXML_XPATH_ENABLED3738typedef struct _xmlXPathContext xmlXPathContext;39typedef xmlXPathContext *xmlXPathContextPtr;40typedef struct _xmlXPathParserContext xmlXPathParserContext;41typedef xmlXPathParserContext *xmlXPathParserContextPtr;4243/**44* The set of XPath error codes.45*/4647typedef enum {48XPATH_EXPRESSION_OK = 0,49XPATH_NUMBER_ERROR,50XPATH_UNFINISHED_LITERAL_ERROR,51XPATH_START_LITERAL_ERROR,52XPATH_VARIABLE_REF_ERROR,53XPATH_UNDEF_VARIABLE_ERROR,54XPATH_INVALID_PREDICATE_ERROR,55XPATH_EXPR_ERROR,56XPATH_UNCLOSED_ERROR,57XPATH_UNKNOWN_FUNC_ERROR,58XPATH_INVALID_OPERAND,59XPATH_INVALID_TYPE,60XPATH_INVALID_ARITY,61XPATH_INVALID_CTXT_SIZE,62XPATH_INVALID_CTXT_POSITION,63XPATH_MEMORY_ERROR,64XPTR_SYNTAX_ERROR,65XPTR_RESOURCE_ERROR,66XPTR_SUB_RESOURCE_ERROR,67XPATH_UNDEF_PREFIX_ERROR,68XPATH_ENCODING_ERROR,69XPATH_INVALID_CHAR_ERROR,70XPATH_INVALID_CTXT,71XPATH_STACK_ERROR,72XPATH_FORBID_VARIABLE_ERROR73} xmlXPathError;7475/*76* A node-set (an unordered collection of nodes without duplicates).77*/78typedef struct _xmlNodeSet xmlNodeSet;79typedef xmlNodeSet *xmlNodeSetPtr;80struct _xmlNodeSet {81int nodeNr; /* number of nodes in the set */82int nodeMax; /* size of the array as allocated */83xmlNodePtr *nodeTab; /* array of nodes in no particular order */84/* @@ with_ns to check wether namespace nodes should be looked at @@ */85};8687/*88* An expression is evaluated to yield an object, which89* has one of the following four basic types:90* - node-set91* - boolean92* - number93* - string94*95* @@ XPointer will add more types !96*/9798typedef enum {99XPATH_UNDEFINED = 0,100XPATH_NODESET = 1,101XPATH_BOOLEAN = 2,102XPATH_NUMBER = 3,103XPATH_STRING = 4,104XPATH_POINT = 5,105XPATH_RANGE = 6,106XPATH_LOCATIONSET = 7,107XPATH_USERS = 8,108XPATH_XSLT_TREE = 9 /* An XSLT value tree, non modifiable */109} xmlXPathObjectType;110111typedef struct _xmlXPathObject xmlXPathObject;112typedef xmlXPathObject *xmlXPathObjectPtr;113struct _xmlXPathObject {114xmlXPathObjectType type;115xmlNodeSetPtr nodesetval;116int boolval;117double floatval;118xmlChar *stringval;119void *user;120int index;121void *user2;122int index2;123};124125/**126* xmlXPathConvertFunc:127* @obj: an XPath object128* @type: the number of the target type129*130* A conversion function is associated to a type and used to cast131* the new type to primitive values.132*133* Returns -1 in case of error, 0 otherwise134*/135typedef int (*xmlXPathConvertFunc) (xmlXPathObjectPtr obj, int type);136137/*138* Extra type: a name and a conversion function.139*/140141typedef struct _xmlXPathType xmlXPathType;142typedef xmlXPathType *xmlXPathTypePtr;143struct _xmlXPathType {144const xmlChar *name; /* the type name */145xmlXPathConvertFunc func; /* the conversion function */146};147148/*149* Extra variable: a name and a value.150*/151152typedef struct _xmlXPathVariable xmlXPathVariable;153typedef xmlXPathVariable *xmlXPathVariablePtr;154struct _xmlXPathVariable {155const xmlChar *name; /* the variable name */156xmlXPathObjectPtr value; /* the value */157};158159/**160* xmlXPathEvalFunc:161* @ctxt: an XPath parser context162* @nargs: the number of arguments passed to the function163*164* An XPath evaluation function, the parameters are on the XPath context stack.165*/166167typedef void (*xmlXPathEvalFunc)(xmlXPathParserContextPtr ctxt,168int nargs);169170/*171* Extra function: a name and a evaluation function.172*/173174typedef struct _xmlXPathFunct xmlXPathFunct;175typedef xmlXPathFunct *xmlXPathFuncPtr;176struct _xmlXPathFunct {177const xmlChar *name; /* the function name */178xmlXPathEvalFunc func; /* the evaluation function */179};180181/**182* xmlXPathAxisFunc:183* @ctxt: the XPath interpreter context184* @cur: the previous node being explored on that axis185*186* An axis traversal function. To traverse an axis, the engine calls187* the first time with cur == NULL and repeat until the function returns188* NULL indicating the end of the axis traversal.189*190* Returns the next node in that axis or NULL if at the end of the axis.191*/192193typedef xmlXPathObjectPtr (*xmlXPathAxisFunc) (xmlXPathParserContextPtr ctxt,194xmlXPathObjectPtr cur);195196/*197* Extra axis: a name and an axis function.198*/199200typedef struct _xmlXPathAxis xmlXPathAxis;201typedef xmlXPathAxis *xmlXPathAxisPtr;202struct _xmlXPathAxis {203const xmlChar *name; /* the axis name */204xmlXPathAxisFunc func; /* the search function */205};206207/**208* xmlXPathFunction:209* @ctxt: the XPath interprestation context210* @nargs: the number of arguments211*212* An XPath function.213* The arguments (if any) are popped out from the context stack214* and the result is pushed on the stack.215*/216217typedef void (*xmlXPathFunction) (xmlXPathParserContextPtr ctxt, int nargs);218219/*220* Function and Variable Lookup.221*/222223/**224* xmlXPathVariableLookupFunc:225* @ctxt: an XPath context226* @name: name of the variable227* @ns_uri: the namespace name hosting this variable228*229* Prototype for callbacks used to plug variable lookup in the XPath230* engine.231*232* Returns the XPath object value or NULL if not found.233*/234typedef xmlXPathObjectPtr (*xmlXPathVariableLookupFunc) (void *ctxt,235const xmlChar *name,236const xmlChar *ns_uri);237238/**239* xmlXPathFuncLookupFunc:240* @ctxt: an XPath context241* @name: name of the function242* @ns_uri: the namespace name hosting this function243*244* Prototype for callbacks used to plug function lookup in the XPath245* engine.246*247* Returns the XPath function or NULL if not found.248*/249typedef xmlXPathFunction (*xmlXPathFuncLookupFunc) (void *ctxt,250const xmlChar *name,251const xmlChar *ns_uri);252253/**254* xmlXPathFlags:255* Flags for XPath engine compilation and runtime256*/257/**258* XML_XPATH_CHECKNS:259*260* check namespaces at compilation261*/262#define XML_XPATH_CHECKNS (1<<0)263/**264* XML_XPATH_NOVAR:265*266* forbid variables in expression267*/268#define XML_XPATH_NOVAR (1<<1)269270/**271* xmlXPathContext:272*273* Expression evaluation occurs with respect to a context.274* he context consists of:275* - a node (the context node)276* - a node list (the context node list)277* - a set of variable bindings278* - a function library279* - the set of namespace declarations in scope for the expression280* Following the switch to hash tables, this need to be trimmed up at281* the next binary incompatible release.282* The node may be modified when the context is passed to libxml2283* for an XPath evaluation so you may need to initialize it again284* before the next call.285*/286287struct _xmlXPathContext {288xmlDocPtr doc; /* The current document */289xmlNodePtr node; /* The current node */290291int nb_variables_unused; /* unused (hash table) */292int max_variables_unused; /* unused (hash table) */293xmlHashTablePtr varHash; /* Hash table of defined variables */294295int nb_types; /* number of defined types */296int max_types; /* max number of types */297xmlXPathTypePtr types; /* Array of defined types */298299int nb_funcs_unused; /* unused (hash table) */300int max_funcs_unused; /* unused (hash table) */301xmlHashTablePtr funcHash; /* Hash table of defined funcs */302303int nb_axis; /* number of defined axis */304int max_axis; /* max number of axis */305xmlXPathAxisPtr axis; /* Array of defined axis */306307/* the namespace nodes of the context node */308xmlNsPtr *namespaces; /* Array of namespaces */309int nsNr; /* number of namespace in scope */310void *user; /* function to free */311312/* extra variables */313int contextSize; /* the context size */314int proximityPosition; /* the proximity position */315316/* extra stuff for XPointer */317int xptr; /* is this an XPointer context? */318xmlNodePtr here; /* for here() */319xmlNodePtr origin; /* for origin() */320321/* the set of namespace declarations in scope for the expression */322xmlHashTablePtr nsHash; /* The namespaces hash table */323xmlXPathVariableLookupFunc varLookupFunc;/* variable lookup func */324void *varLookupData; /* variable lookup data */325326/* Possibility to link in an extra item */327void *extra; /* needed for XSLT */328329/* The function name and URI when calling a function */330const xmlChar *function;331const xmlChar *functionURI;332333/* function lookup function and data */334xmlXPathFuncLookupFunc funcLookupFunc;/* function lookup func */335void *funcLookupData; /* function lookup data */336337/* temporary namespace lists kept for walking the namespace axis */338xmlNsPtr *tmpNsList; /* Array of namespaces */339int tmpNsNr; /* number of namespaces in scope */340341/* error reporting mechanism */342void *userData; /* user specific data block */343xmlStructuredErrorFunc error; /* the callback in case of errors */344xmlError lastError; /* the last error */345xmlNodePtr debugNode; /* the source node XSLT */346347/* dictionary */348xmlDictPtr dict; /* dictionary if any */349350int flags; /* flags to control compilation */351352/* Cache for reusal of XPath objects */353void *cache;354};355356/*357* The structure of a compiled expression form is not public.358*/359360typedef struct _xmlXPathCompExpr xmlXPathCompExpr;361typedef xmlXPathCompExpr *xmlXPathCompExprPtr;362363/**364* xmlXPathParserContext:365*366* An XPath parser context. It contains pure parsing informations,367* an xmlXPathContext, and the stack of objects.368*/369struct _xmlXPathParserContext {370const xmlChar *cur; /* the current char being parsed */371const xmlChar *base; /* the full expression */372373int error; /* error code */374375xmlXPathContextPtr context; /* the evaluation context */376xmlXPathObjectPtr value; /* the current value */377int valueNr; /* number of values stacked */378int valueMax; /* max number of values stacked */379xmlXPathObjectPtr *valueTab; /* stack of values */380381xmlXPathCompExprPtr comp; /* the precompiled expression */382int xptr; /* it this an XPointer expression */383xmlNodePtr ancestor; /* used for walking preceding axis */384385int valueFrame; /* used to limit Pop on the stack */386};387388/************************************************************************389* *390* Public API *391* *392************************************************************************/393394/**395* Objects and Nodesets handling396*/397398XMLPUBVAR double xmlXPathNAN;399XMLPUBVAR double xmlXPathPINF;400XMLPUBVAR double xmlXPathNINF;401402/* These macros may later turn into functions */403/**404* xmlXPathNodeSetGetLength:405* @ns: a node-set406*407* Implement a functionality similar to the DOM NodeList.length.408*409* Returns the number of nodes in the node-set.410*/411#define xmlXPathNodeSetGetLength(ns) ((ns) ? (ns)->nodeNr : 0)412/**413* xmlXPathNodeSetItem:414* @ns: a node-set415* @index: index of a node in the set416*417* Implements a functionality similar to the DOM NodeList.item().418*419* Returns the xmlNodePtr at the given @index in @ns or NULL if420* @index is out of range (0 to length-1)421*/422#define xmlXPathNodeSetItem(ns, index) \423((((ns) != NULL) && \424((index) >= 0) && ((index) < (ns)->nodeNr)) ? \425(ns)->nodeTab[(index)] \426: NULL)427/**428* xmlXPathNodeSetIsEmpty:429* @ns: a node-set430*431* Checks whether @ns is empty or not.432*433* Returns %TRUE if @ns is an empty node-set.434*/435#define xmlXPathNodeSetIsEmpty(ns) \436(((ns) == NULL) || ((ns)->nodeNr == 0) || ((ns)->nodeTab == NULL))437438439XMLPUBFUN void XMLCALL440xmlXPathFreeObject (xmlXPathObjectPtr obj);441XMLPUBFUN xmlNodeSetPtr XMLCALL442xmlXPathNodeSetCreate (xmlNodePtr val);443XMLPUBFUN void XMLCALL444xmlXPathFreeNodeSetList (xmlXPathObjectPtr obj);445XMLPUBFUN void XMLCALL446xmlXPathFreeNodeSet (xmlNodeSetPtr obj);447XMLPUBFUN xmlXPathObjectPtr XMLCALL448xmlXPathObjectCopy (xmlXPathObjectPtr val);449XMLPUBFUN int XMLCALL450xmlXPathCmpNodes (xmlNodePtr node1,451xmlNodePtr node2);452/**453* Conversion functions to basic types.454*/455XMLPUBFUN int XMLCALL456xmlXPathCastNumberToBoolean (double val);457XMLPUBFUN int XMLCALL458xmlXPathCastStringToBoolean (const xmlChar * val);459XMLPUBFUN int XMLCALL460xmlXPathCastNodeSetToBoolean(xmlNodeSetPtr ns);461XMLPUBFUN int XMLCALL462xmlXPathCastToBoolean (xmlXPathObjectPtr val);463464XMLPUBFUN double XMLCALL465xmlXPathCastBooleanToNumber (int val);466XMLPUBFUN double XMLCALL467xmlXPathCastStringToNumber (const xmlChar * val);468XMLPUBFUN double XMLCALL469xmlXPathCastNodeToNumber (xmlNodePtr node);470XMLPUBFUN double XMLCALL471xmlXPathCastNodeSetToNumber (xmlNodeSetPtr ns);472XMLPUBFUN double XMLCALL473xmlXPathCastToNumber (xmlXPathObjectPtr val);474475XMLPUBFUN xmlChar * XMLCALL476xmlXPathCastBooleanToString (int val);477XMLPUBFUN xmlChar * XMLCALL478xmlXPathCastNumberToString (double val);479XMLPUBFUN xmlChar * XMLCALL480xmlXPathCastNodeToString (xmlNodePtr node);481XMLPUBFUN xmlChar * XMLCALL482xmlXPathCastNodeSetToString (xmlNodeSetPtr ns);483XMLPUBFUN xmlChar * XMLCALL484xmlXPathCastToString (xmlXPathObjectPtr val);485486XMLPUBFUN xmlXPathObjectPtr XMLCALL487xmlXPathConvertBoolean (xmlXPathObjectPtr val);488XMLPUBFUN xmlXPathObjectPtr XMLCALL489xmlXPathConvertNumber (xmlXPathObjectPtr val);490XMLPUBFUN xmlXPathObjectPtr XMLCALL491xmlXPathConvertString (xmlXPathObjectPtr val);492493/**494* Context handling.495*/496XMLPUBFUN xmlXPathContextPtr XMLCALL497xmlXPathNewContext (xmlDocPtr doc);498XMLPUBFUN void XMLCALL499xmlXPathFreeContext (xmlXPathContextPtr ctxt);500XMLPUBFUN int XMLCALL501xmlXPathContextSetCache(xmlXPathContextPtr ctxt,502int active,503int value,504int options);505/**506* Evaluation functions.507*/508XMLPUBFUN long XMLCALL509xmlXPathOrderDocElems (xmlDocPtr doc);510XMLPUBFUN int XMLCALL511xmlXPathSetContextNode (xmlNodePtr node,512xmlXPathContextPtr ctx);513XMLPUBFUN xmlXPathObjectPtr XMLCALL514xmlXPathNodeEval (xmlNodePtr node,515const xmlChar *str,516xmlXPathContextPtr ctx);517XMLPUBFUN xmlXPathObjectPtr XMLCALL518xmlXPathEval (const xmlChar *str,519xmlXPathContextPtr ctx);520XMLPUBFUN xmlXPathObjectPtr XMLCALL521xmlXPathEvalExpression (const xmlChar *str,522xmlXPathContextPtr ctxt);523XMLPUBFUN int XMLCALL524xmlXPathEvalPredicate (xmlXPathContextPtr ctxt,525xmlXPathObjectPtr res);526/**527* Separate compilation/evaluation entry points.528*/529XMLPUBFUN xmlXPathCompExprPtr XMLCALL530xmlXPathCompile (const xmlChar *str);531XMLPUBFUN xmlXPathCompExprPtr XMLCALL532xmlXPathCtxtCompile (xmlXPathContextPtr ctxt,533const xmlChar *str);534XMLPUBFUN xmlXPathObjectPtr XMLCALL535xmlXPathCompiledEval (xmlXPathCompExprPtr comp,536xmlXPathContextPtr ctx);537XMLPUBFUN int XMLCALL538xmlXPathCompiledEvalToBoolean(xmlXPathCompExprPtr comp,539xmlXPathContextPtr ctxt);540XMLPUBFUN void XMLCALL541xmlXPathFreeCompExpr (xmlXPathCompExprPtr comp);542#endif /* LIBXML_XPATH_ENABLED */543#if defined(LIBXML_XPATH_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED)544XMLPUBFUN void XMLCALL545xmlXPathInit (void);546XMLPUBFUN int XMLCALL547xmlXPathIsNaN (double val);548XMLPUBFUN int XMLCALL549xmlXPathIsInf (double val);550551#ifdef __cplusplus552}553#endif554555#endif /* LIBXML_XPATH_ENABLED or LIBXML_SCHEMAS_ENABLED*/556#endif /* ! __XML_XPATH_H__ */557558559