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