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