1 * Summary: XML Path Language implementation 2 * Description: API for the XML Path Language implementation 3 * 4 * XML Path Language implementation 5 * XPath is a language for addressing parts of an XML document, 6 * designed to be used by both XSLT and XPointer 7 * http://www.w3.org/TR/xpath 8 * 9 * Implements 10 * W3C Recommendation 16 November 1999 11 * http://www.w3.org/TR/1999/REC-xpath-19991116 12 * 13 * Copy: See Copyright for the status of this software. 14 * 15 * Author: Patrick Monnerat <pm@datasphere.ch>, DATASPHERE S.A. 16 17 /if not defined(XML_XPATH_H__) 18 /define XML_XPATH_H__ 19 20 /include "libxmlrpg/xmlversion" 21 22 /if defined(LIBXML_XPATH_ENABLED) 23 24 /include "libxmlrpg/xmlTypesC" 25 /include "libxmlrpg/xmlerror" 26 /include "libxmlrpg/tree" 27 /include "libxmlrpg/hash" 28 /endif LIBXML_XPATH_ENABLED 29 30 /if defined(LIBXML_XPATH_ENABLED) 31 32 d xmlXPathContextPtr... 33 d s * based(######typedef######) 34 35 d xmlXPathParserContextPtr... 36 d s * based(######typedef######) 37 38 * The set of XPath error codes. 39 40 d xmlXPathError s based(######typedef######) 41 d like(xmlCenum) 42 d XPATH_EXPRESSION_OK... 43 d c 0 44 d XPATH_NUMBER_ERROR... 45 d c 1 46 d XPATH_UNFINISHED_LITERAL_ERROR... 47 d c 2 48 d XPATH_START_LITERAL_ERROR... 49 d c 3 50 d XPATH_VARIABLE_REF_ERROR... 51 d c 4 52 d XPATH_UNDEF_VARIABLE_ERROR... 53 d c 5 54 d XPATH_INVALID_PREDICATE_ERROR... 55 d c 6 56 d XPATH_EXPR_ERROR... 57 d c 7 58 d XPATH_UNCLOSED_ERROR... 59 d c 8 60 d XPATH_UNKNOWN_FUNC_ERROR... 61 d c 9 62 d XPATH_INVALID_OPERAND... 63 d c 10 64 d XPATH_INVALID_TYPE... 65 d c 11 66 d XPATH_INVALID_ARITY... 67 d c 12 68 d XPATH_INVALID_CTXT_SIZE... 69 d c 13 70 d XPATH_INVALID_CTXT_POSITION... 71 d c 14 72 d XPATH_MEMORY_ERROR... 73 d c 15 74 d XPTR_SYNTAX_ERROR... 75 d c 16 76 d XPTR_RESOURCE_ERROR... 77 d c 17 78 d XPTR_SUB_RESOURCE_ERROR... 79 d c 18 80 d XPATH_UNDEF_PREFIX_ERROR... 81 d c 19 82 d XPATH_ENCODING_ERROR... 83 d c 20 84 d XPATH_INVALID_CHAR_ERROR... 85 d c 21 86 d XPATH_INVALID_CTXT... 87 d c 22 88 d XPATH_STACK_ERROR... 89 d c 23 90 d XPATH_FORBID_VARIABLE_ERROR... 91 d c 24 92 93 * A node-set (an unordered collection of nodes without duplicates). 94 95 d xmlNodeSetPtr s * based(######typedef######) 96 97 d xmlNodeSet ds based(xmlNodeSetPtr) 98 d align qualified 99 d nodeNr like(xmlCint) Set node count 100 d nodeMax like(xmlCint) Max # nodes in set 101 d nodeTab * xmlNodePtr * 102 103 * An expression is evaluated to yield an object, which 104 * has one of the following four basic types: 105 * - node-set 106 * - boolean 107 * - number 108 * - string 109 * 110 * @@ XPointer will add more types ! 111 112 d xmlXPathObjectType... 113 d s based(######typedef######) 114 d like(xmlCenum) 115 d XPATH_UNDEFINED... 116 d c 0 117 d XPATH_NODESET c 1 118 d XPATH_BOOLEAN c 2 119 d XPATH_NUMBER c 3 120 d XPATH_STRING c 4 121 d XPATH_POINT c 5 122 d XPATH_RANGE c 6 123 d XPATH_LOCATIONSET... 124 d c 7 125 d XPATH_USERS c 8 126 d XPATH_XSLT_TREE... R/O XSLT value tree 127 d c 9 128 129 d xmlXPathObjectPtr... 130 d s * based(######typedef######) 131 132 d xmlXPathObject ds based(xmlXPathObjectPtr) 133 d align qualified 134 d type like(xmlXPathObjectType) 135 d nodesetval like(xmlNodeSetPtr) 136 d boolval like(xmlCint) 137 d floatval like(xmlCdouble) 138 d stringval * xmlChar * 139 d user * void * 140 d index like(xmlCint) 141 d user2 * void * 142 d index2 like(xmlCint) 143 144 * xmlXPathConvertFunc: 145 * @obj: an XPath object 146 * @type: the number of the target type 147 * 148 * A conversion function is associated to a type and used to cast 149 * the new type to primitive values. 150 * 151 * Returns -1 in case of error, 0 otherwise 152 153 d xmlXPathConvertFunc... 154 d s * based(######typedef######) 155 d procptr 156 157 * Extra type: a name and a conversion function. 158 159 d xmlXPathTypePtr... 160 d s * based(######typedef######) 161 162 d xmlXPathType ds based(xmlXPathTypePtr) 163 d align qualified 164 d name * The type name 165 d func like(xmlXPathConvertFunc) Conversion function 166 167 * Extra variable: a name and a value. 168 169 d xmlXPathVariablePtr... 170 d s * based(######typedef######) 171 172 d xmlXPathVariable... 173 d ds based(xmlXPathVariablePtr) 174 d align qualified 175 d name * The variable name 176 d value like(xmlXPathObjectPtr) The value 177 178 * xmlXPathEvalFunc: 179 * @ctxt: an XPath parser context 180 * @nargs: the number of arguments passed to the function 181 * 182 * An XPath evaluation function, the parameters are on the XPath 183 * context stack. 184 185 d xmlXPathEvalFunc... 186 d s * based(######typedef######) 187 d procptr 188 189 * Extra function: a name and an evaluation function. 190 191 d xmlXPathFuncPtr... 192 d s * based(######typedef######) 193 194 d xmlXPathFunct ds based(xmlXPathFuncPtr) 195 d align qualified 196 d name * The function name 197 d func like(xmlXPathEvalFunc) Evaluation function 198 199 * xmlXPathAxisFunc: 200 * @ctxt: the XPath interpreter context 201 * @cur: the previous node being explored on that axis 202 * 203 * An axis traversal function. To traverse an axis, the engine calls 204 * the first time with cur == NULL and repeat until the function returns 205 * NULL indicating the end of the axis traversal. 206 * 207 * Returns the next node in that axis or NULL if at the end of the axis. 208 209 d xmlXPathAxisFunc... 210 d s * based(######typedef######) 211 d procptr 212 213 * Extra axis: a name and an axis function. 214 215 d xmlXPathAxisPtr... 216 d s * based(######typedef######) 217 218 d xmlXPathAxis ds based(xmlXPathAxisPtr) 219 d align qualified 220 d name * The axis name 221 d func like(xmlXPathAxisFunc) The search function 222 223 * xmlXPathFunction: 224 * @ctxt: the XPath interprestation context 225 * @nargs: the number of arguments 226 * 227 * An XPath function. 228 * The arguments (if any) are popped out from the context stack 229 * and the result is pushed on the stack. 230 231 d xmlXPathFunction... 232 d s * based(######typedef######) 233 d procptr 234 235 * Function and Variable Lookup. 236 237 * xmlXPathVariableLookupFunc: 238 * @ctxt: an XPath context 239 * @name: name of the variable 240 * @ns_uri: the namespace name hosting this variable 241 * 242 * Prototype for callbacks used to plug variable lookup in the XPath 243 * engine. 244 * 245 * Returns the XPath object value or NULL if not found. 246 247 d xmlXPathVariableLookupFunc... 248 d s * based(######typedef######) 249 d procptr 250 251 * xmlXPathFuncLookupFunc: 252 * @ctxt: an XPath context 253 * @name: name of the function 254 * @ns_uri: the namespace name hosting this function 255 * 256 * Prototype for callbacks used to plug function lookup in the XPath 257 * engine. 258 * 259 * Returns the XPath function or NULL if not found. 260 261 d xmlXPathFuncLookupFunc... 262 d s * based(######typedef######) 263 d procptr 264 265 * xmlXPathFlags: 266 * Flags for XPath engine compilation and runtime 267 268 * XML_XPATH_CHECKNS: 269 * 270 * check namespaces at compilation 271 272 d XML_XPATH_CHECKNS... 273 d c X'0001' 274 275 * XML_XPATH_NOVAR: 276 * 277 * forbid variables in expression 278 279 d XML_XPATH_NOVAR... 280 d c X'0002' 281 282 * xmlXPathContext: 283 * 284 * Expression evaluation occurs with respect to a context. 285 * he context consists of: 286 * - a node (the context node) 287 * - a node list (the context node list) 288 * - a set of variable bindings 289 * - a function library 290 * - the set of namespace declarations in scope for the expression 291 * Following the switch to hash tables, this need to be trimmed up at 292 * the next binary incompatible release. 293 * The node may be modified when the context is passed to libxml2 294 * for an XPath evaluation so you may need to initialize it again 295 * before the next call. 296 297 d xmlXPathContext... 298 d ds based(xmlXPathContextPtr) 299 d align qualified 300 d doc like(xmlDocPtr) Current document 301 d node like(xmlNodePtr) Current node 302 * 303 d nb_variables_unused... Unused (hash table) 304 d like(xmlCint) 305 d max_variables_unused... Unused (hash table) 306 d like(xmlCint) 307 d varHash like(xmlHashTablePtr) Defined variables 308 * 309 d nb_types like(xmlCint) # of defined types 310 d max_types like(xmlCint) Max number of types 311 d types like(xmlXPathTypePtr) Defined types array 312 * 313 d nb_funcs_unused... Unused (hash table) 314 d like(xmlCint) 315 d max_funcs_unused... Unused (hash table) 316 d like(xmlCint) 317 d funcHash like(xmlHashTablePtr) Defined functions 318 * 319 d nb_axis like(xmlCint) # of defined axis 320 d max_axis like(xmlCint) Max number of axis 321 d axis like(xmlXPathAxisPtr) Defined axis array 322 * 323 * the namespace nodes of the context node 324 * 325 d namespaces * xmlNsPtr * 326 d nsNr like(xmlCint) # scope namespaces 327 d user * procptr Function to free 328 * 329 * extra variables 330 * 331 d contextSize like(xmlCint) The context size 332 d proximityPosition... 333 d like(xmlCint) 334 * 335 * extra stuff for XPointer 336 * 337 d xptr like(xmlCint) XPointer context ? 338 d here like(xmlNodePtr) For here() 339 d origin like(xmlNodePtr) For origin() 340 * 341 * the set of namespace declarations in scope for the expression 342 * 343 d nsHash like(xmlHashTablePtr) Namespace hashtable 344 d varLookupFunc like(xmlXPathVariableLookupFunc) Var lookup function 345 d varLookupData * void * 346 * 347 * Possibility to link in an extra item 348 * 349 d extra * void * 350 * 351 * The function name and URI when calling a function 352 * 353 d function * const xmlChar * 354 d functionURI * const xmlChar * 355 * 356 * function lookup function and data 357 * 358 d funcLookupFunc... Func lookup func 359 d like(xmlXPathVariableLookupFunc) 360 d funcLookupData... void * 361 d * 362 * 363 * temporary namespace lists kept for walking the namespace axis 364 * 365 d tmpNsList * xmlNsPtr * 366 d tmpNsNr like(xmlCint) # scope namespaces 367 * 368 * error reporting mechanism 369 * 370 d userData * void * 371 d error like(xmlStructuredErrorFunc) Error callback 372 d lastError likeds(xmlError) The last error 373 d debugNode like(xmlNodePtr) XSLT source node 374 * 375 * dictionary 376 * 377 d dict like(xmlDictPtr) Dictionary if any 378 * 379 d flags like(xmlCint) Compilation control 380 * 381 * Cache for reusal of XPath objects 382 * 383 d cache * void * 384 385 * The structure of a compiled expression form is not public. 386 387 d xmlXPathCompExprPtr... 388 d s * based(######typedef######) 389 390 * xmlXPathParserContext: 391 * 392 * An XPath parser context. It contains pure parsing informations, 393 * an xmlXPathContext, and the stack of objects. 394 395 d xmlXPathParserContext... 396 d ds based(xmlXPathParserContextPtr) 397 d align qualified 398 d cur * const xmlChar * 399 d base * const xmlChar * 400 * 401 d error like(xmlCint) Error code 402 * 403 d context like(xmlXPathContextPtr) Evaluation context 404 d value like(xmlXPathObjectPtr) The current value 405 d valueNr like(xmlCint) Value stack depth 406 d valueMax like(xmlCint) Max stack depth 407 d valueTab * xmlXPathObjectPtr * 408 * 409 d comp like(xmlXPathCompExprPtr) Precompiled expr. 410 d xptr like(xmlCint) XPointer expression? 411 d ancestor like(xmlNodePtr) To walk prec. axis 412 * 413 d valueFrame like(xmlCint) Limit stack pop 414 415 ************************************************************************** 416 * * 417 * Public API * 418 * * 419 ************************************************************************** 420 421 * Objects and Nodesets handling 422 423 d xmlXPathNAN s import('xmlXPathNAN') 424 d like(xmlCdouble) 425 426 d xmlXPathPINF s import('xmlXPathPINF') 427 d like(xmlCdouble) 428 429 d xmlXPathNINF s import('xmlXPathNINF') 430 d like(xmlCdouble) 431 432 d xmlXPathFreeObject... 433 d pr extproc('xmlXPathFreeObject') 434 d obj value like(xmlXPathObjectPtr) 435 436 d xmlXPathNodeSetCreate... 437 d pr extproc('xmlXPathNodeSetCreate') 438 d like(xmlNodeSetPtr) 439 d val value like(xmlNodePtr) 440 441 d xmlXPathFreeNodeSetList... 442 d pr extproc('xmlXPathFreeNodeSetList') 443 d obj value like(xmlXPathObjectPtr) 444 445 d xmlXPathFreeNodeSet... 446 d pr extproc('xmlXPathFreeNodeSet') 447 d obj value like(xmlNodeSetPtr) 448 449 d xmlXPathObjectCopy... 450 d pr extproc('xmlXPathObjectCopy') 451 d like(xmlXPathObjectPtr) 452 d val value like(xmlXPathObjectPtr) 453 454 d xmlXPathCmpNodes... 455 d pr extproc('xmlXPathCmpNodes') 456 d like(xmlCint) 457 d node1 value like(xmlNodePtr) 458 d node2 value like(xmlNodePtr) 459 460 * Conversion functions to basic types. 461 462 d xmlXPathCastNumberToBoolean... 463 d pr extproc( 464 d 'xmlXPathCastNumberToBoolean') 465 d like(xmlCint) 466 d val value like(xmlCdouble) 467 468 d xmlXPathCastStringToBoolean... 469 d pr extproc( 470 d 'xmlXPathCastStringToBoolean') 471 d like(xmlCint) 472 d val * value options(*string) const xmlChar * 473 474 d xmlXPathCastNodeSetToBoolean... 475 d pr extproc( 476 d 'xmlXPathCastNodeSetToBoolean') 477 d like(xmlCint) 478 d ns value like(xmlNodeSetPtr) 479 480 d xmlXPathCastToBoolean... 481 d pr extproc('xmlXPathCastToBoolean') 482 d like(xmlCint) 483 d val value like(xmlXPathObjectPtr) 484 485 d xmlXPathCastBooleanToNumber... 486 d pr extproc( 487 d 'xmlXPathCastBooleanToNumber') 488 d like(xmlCdouble) 489 d val value like(xmlCint) 490 491 d xmlXPathCastStringToNumber... 492 d pr extproc('xmlXPathCastStringToNumber') 493 d like(xmlCdouble) 494 d val * value options(*string) const xmlChar * 495 496 d xmlXPathCastNodeToNumber... 497 d pr extproc('xmlXPathCastNodeToNumber') 498 d like(xmlCdouble) 499 d node value like(xmlNodePtr) 500 501 d xmlXPathCastNodeSetToNumber... 502 d pr extproc( 503 d 'xmlXPathCastNodeSetToNumber') 504 d like(xmlCdouble) 505 d ns value like(xmlNodeSetPtr) 506 507 d xmlXPathCastToNumber... 508 d pr extproc('xmlXPathCastToNumber') 509 d like(xmlCdouble) 510 d val value like(xmlXPathObjectPtr) 511 512 d xmlXPathCastBooleanToString... 513 d pr * extproc( xmlChar * 514 d 'xmlXPathCastBooleanToString') 515 d val value like(xmlCint) 516 517 d xmlXPathCastNumberToString... 518 d pr * extproc('xmlXPathCastNumberToString')xmlChar * 519 d val value like(xmlCdouble) 520 521 d xmlXPathCastNodeToString... 522 d pr * extproc('xmlXPathCastNodeToString') xmlChar * 523 d node value like(xmlNodePtr) 524 525 d xmlXPathCastNodeSetToString... 526 d pr * extproc('xmlXPathCastNodeSetToString'xmlChar * 527 d ) 528 d ns value like(xmlNodeSetPtr) 529 530 d xmlXPathCastToString... 531 d pr * extproc('xmlXPathCastToString') xmlChar * 532 d val value like(xmlXPathObjectPtr) 533 534 d xmlXPathConvertBoolean... 535 d pr extproc('xmlXPathConvertBoolean') 536 d like(xmlXPathObjectPtr) 537 d val value like(xmlXPathObjectPtr) 538 539 d xmlXPathConvertNumber... 540 d pr extproc('xmlXPathConvertNumber') 541 d like(xmlXPathObjectPtr) 542 d val value like(xmlXPathObjectPtr) 543 544 d xmlXPathConvertString... 545 d pr extproc('xmlXPathConvertString') 546 d like(xmlXPathObjectPtr) 547 d val value like(xmlXPathObjectPtr) 548 549 * Context handling. 550 551 d xmlXPathNewContext... 552 d pr extproc('xmlXPathNewContext') 553 d like(xmlXPathContextPtr) 554 d doc value like(xmlDocPtr) 555 556 d xmlXPathFreeContext... 557 d pr extproc('xmlXPathFreeContext') 558 d ctxt value like(xmlXPathContextPtr) 559 560 d xmlXPathContextSetCache... 561 d pr extproc('xmlXPathContextSetCache') 562 d like(xmlCint) 563 d ctxt value like(xmlXPathContextPtr) 564 d active value like(xmlCint) 565 d value value like(xmlCint) 566 d options value like(xmlCint) 567 568 * Evaluation functions. 569 570 d xmlXPathOrderDocElems... 571 d pr extproc('xmlXPathOrderDocElems') 572 d like(xmlClong) 573 d doc value like(xmlDocPtr) 574 575 d xmlXPathSetContextNode... 576 d pr extproc('xmlXPathSetContextNode') 577 d like(xmlCint) 578 d node value like(xmlNodePtr) 579 d ctx value like(xmlXPathContextPtr) 580 581 d xmlXPathNodeEval... 582 d pr extproc('xmlXPathNodeEval') 583 d like(xmlXPathObjectPtr) 584 d node value like(xmlNodePtr) 585 d str * value options(*string) const xmlChar * 586 d ctx value like(xmlXPathContextPtr) 587 588 d xmlXPathEval pr extproc('xmlXPathEval') 589 d like(xmlXPathObjectPtr) 590 d str * value options(*string) const xmlChar * 591 d ctx value like(xmlXPathContextPtr) 592 593 d xmlXPathEvalExpression... 594 d pr extproc('xmlXPathEvalExpression') 595 d like(xmlXPathObjectPtr) 596 d str * value options(*string) const xmlChar * 597 d ctxt value like(xmlXPathContextPtr) 598 599 d xmlXPathEvalPredicate... 600 d pr extproc('xmlXPathEvalPredicate') 601 d like(xmlCint) 602 d ctxt value like(xmlXPathContextPtr) 603 d res value like(xmlXPathObjectPtr) 604 605 * Separate compilation/evaluation entry points. 606 607 d xmlXPathCompile... 608 d pr extproc('xmlXPathCompile') 609 d like(xmlXPathCompExprPtr) 610 d str * value options(*string) const xmlChar * 611 612 d xmlXPathCtxtCompile... 613 d pr extproc('xmlXPathCtxtCompile') 614 d like(xmlXPathCompExprPtr) 615 d ctxt value like(xmlXPathContextPtr) 616 d str * value options(*string) const xmlChar * 617 618 d xmlXPathCompiledEval... 619 d pr extproc('xmlXPathCompiledEval') 620 d like(xmlXPathObjectPtr) 621 d comp value like(xmlXPathCompExprPtr) 622 d ctx value like(xmlXPathContextPtr) 623 624 d xmlXPathCompiledEvalToBoolean... 625 d pr extproc( 626 d 'xmlXPathCompiledEvalToBoolean') 627 d like(xmlCint) 628 d comp value like(xmlXPathCompExprPtr) 629 d ctxt value like(xmlXPathContextPtr) 630 631 d xmlXPathFreeCompExpr... 632 d pr extproc('xmlXPathFreeCompExpr') 633 d comp value like(xmlXPathCompExprPtr) 634 /endif LIBXML_XPATH_ENABLED 635 636 /undefine XML_TESTVAL 637 /if defined(LIBXML_XPATH_ENABLED) 638 /define XML_TESTVAL 639 /elseif defined(LIBXML_SCHEMAS_ENABLED) 640 /define XML_TESTVAL 641 /endif 642 /if defined(XML_TESTVAL) 643 d xmlXPathInit pr extproc('xmlXPathInit') 644 645 d xmlXPathIsNaN pr extproc('xmlXPathIsNaN') 646 d like(xmlCint) 647 d val value like(xmlCdouble) 648 649 d xmlXPathIsInf pr extproc('xmlXPathIsInf') 650 d like(xmlCint) 651 d val value like(xmlCdouble) 652 653 /undefine XML_TESTVAL 654 /endif 655 656 * C macros implemented as procedures for ILE/RPG support. 657 658 /if defined(LIBXML_XPATH_ENABLED) 659 d xmlXPathNodeSetGetLength... 660 d pr extproc('__xmlXPathNodeSetGetLength') 661 d like(xmlCint) 662 d ns value like(xmlNodeSetPtr) 663 664 d xmlXPathNodeSetItem... 665 d pr extproc('__xmlXPathNodeSetItem') 666 d like(xmlNodePtr) 667 d ns value like(xmlNodeSetPtr) 668 d index value like(xmlCint) 669 670 d xmlXPathNodeSetIsEmpty... 671 d pr extproc('__xmlXPathNodeSetIsEmpty') 672 d like(xmlCint) 673 d ns value like(xmlNodeSetPtr) 674 /endif LIBXML_XPATH_ENABLED 675 /endif XML_XPATH_H__ 676