Changeset 43 for ccr/trunk/p/GPLXPATH.m
- Timestamp:
- Jul 5, 2008, 11:49:50 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ccr/trunk/p/GPLXPATH.m
r39 r43 1 1 GPLXPATH ; CCDCCR/GPL - XPATH XML manipulation utilities; 6/1/08 2 ;;0.2;CCDCCR;nopatch;noreleasedate2 ;;0.2;CCDCCR;nopatch;noreleasedate 3 3 W "This is an XML XPATH utility library",! 4 4 W ! … … 24 24 ; VAL AND STK ARE PASSED BY REFERENCE 25 25 ; 26 I @STK@(0)<1 S VAL="",@STK@(0)=0 Q ; IF ARRAY IS EMPTY 27 I @STK@(0)>0 D 26 I @STK@(0)<1 D ; IF ARRAY IS EMPTY 27 . S VAL="" 28 . S @STK@(0)=0 29 I @STK@(0)>0 D ; 28 30 . S VAL=@STK@(@STK@(0)) 29 31 . K @STK@(@STK@(0)) … … 243 245 I DEBUG W "DOING INSERT ",INSXML,INSNEW,INSXPATH,! 244 246 I DEBUG F G1=1:1:@INSXML@(0) W @INSXML@(G1),! 245 I '$D(@INSXML@(0)) D Q; INSERT INTO AN EMPTY ARRAY247 I '$D(@INSXML@(0)) D ; INSERT INTO AN EMPTY ARRAY 246 248 . D CP^GPLXPATH(INSNEW,INSXML) ; JUST COPY INTO THE OUTPUT 247 249 I $D(@INSXML@(0)) D ; IF ORIGINAL ARRAY IS NOT EMPTY 248 250 . I $D(INSXPATH) D ; XPATH PROVIDED 249 251 . . D QOPEN("INSBLD",INSXML,INSXPATH) ; COPY THE BEFORE 250 . . I DEBUG ZWR INSBLD252 . . I DEBUG D PARY^GPLXPATH("INSBLD") 251 253 . I '$D(INSXPATH) D ; NO XPATH PROVIDED, OPEN AT ROOT 252 254 . . D QOPEN("INSBLD",INSXML,"//") ; OPEN WITH ROOT XPATH … … 295 297 D QUEUE("REBLD",REXML,XLAST,@REXML@(0)) ; THE REST 296 298 I DEBUG W "REPALCE PREBUILD",! 297 I DEBUG ZWR REBLD299 I DEBUG D PARY("REBLD") 298 300 D BUILD("REBLD","RTMP") 299 301 K @REXML ; KILL WHAT WAS THERE … … 362 364 Q 363 365 ; 364 ;;><TEST>365 ;;><INIT>366 ;;>>>K GPL S GPL=""367 ;;>>>D PUSH^GPLXPATH("GPL","FIRST")368 ;;>>>D PUSH^GPLXPATH("GPL","SECOND")369 ;;>>>D PUSH^GPLXPATH("GPL","THIRD")370 ;;>>>D PUSH^GPLXPATH("GPL","FOURTH")371 ;;>>?GPL(0)=4372 ;;><INITXML>373 ;;>>>K GXML S GXML=""374 ;;>>>D PUSH^GPLXPATH("GXML","<FIRST>")375 ;;>>>D PUSH^GPLXPATH("GXML","<SECOND>")376 ;;>>>D PUSH^GPLXPATH("GXML","<THIRD>")377 ;;>>>D PUSH^GPLXPATH("GXML","<FOURTH>@@DATA1@@</FOURTH>")378 ;;>>>D PUSH^GPLXPATH("GXML","<FIFTH>")379 ;;>>>D PUSH^GPLXPATH("GXML","@@DATA2@@")380 ;;>>>D PUSH^GPLXPATH("GXML","</FIFTH>")381 ;;>>>D PUSH^GPLXPATH("GXML","<SIXTH ID=""SELF"" />")382 ;;>>>D PUSH^GPLXPATH("GXML","</THIRD>")383 ;;>>>D PUSH^GPLXPATH("GXML","<SECOND>")384 ;;>>>D PUSH^GPLXPATH("GXML","</SECOND>")385 ;;>>>D PUSH^GPLXPATH("GXML","</SECOND>")386 ;;>>>D PUSH^GPLXPATH("GXML","</FIRST>")387 ;;><INITXML2>388 ;;>>>K GXML S GXML=""389 ;;>>>D PUSH^GPLXPATH("GXML","<FIRST>")390 ;;>>>D PUSH^GPLXPATH("GXML","<SECOND>")391 ;;>>>D PUSH^GPLXPATH("GXML","<THIRD>")392 ;;>>>D PUSH^GPLXPATH("GXML","<FOURTH>DATA1</FOURTH>")393 ;;>>>D PUSH^GPLXPATH("GXML","<FOURTH>")394 ;;>>>D PUSH^GPLXPATH("GXML","DATA2")395 ;;>>>D PUSH^GPLXPATH("GXML","</FOURTH>")396 ;;>>>D PUSH^GPLXPATH("GXML","</THIRD>")397 ;;>>>D PUSH^GPLXPATH("GXML","<_SECOND>")398 ;;>>>D PUSH^GPLXPATH("GXML","<FOURTH>DATA3</FOURTH>")399 ;;>>>D PUSH^GPLXPATH("GXML","</_SECOND>")400 ;;>>>D PUSH^GPLXPATH("GXML","</SECOND>")401 ;;>>>D PUSH^GPLXPATH("GXML","</FIRST>")402 ;;><PUSHPOP>403 ;;>>>D ZLOAD^GPLUNIT("ZTMP","GPLXPATH")404 ;;>>>D ZTEST^GPLUNIT(.ZTMP,"INIT")405 ;;>>?GPL(GPL(0))="FOURTH"406 ;;>>>D POP^GPLXPATH("GPL",.GX)407 ;;>>?GX="FOURTH"408 ;;>>?GPL(GPL(0))="THIRD"409 ;;>>>D POP^GPLXPATH("GPL",.GX)410 ;;>>?GX="THIRD"411 ;;>>?GPL(GPL(0))="SECOND"412 ;;><MKMDX>413 ;;>>>D ZLOAD^GPLUNIT("ZTMP","GPLXPATH")414 ;;>>>D ZTEST^GPLUNIT(.ZTMP,"INIT")415 ;;>>>S GX=""416 ;;>>>D MKMDX^GPLXPATH("GPL",.GX)417 ;;>>?GX="//FIRST/SECOND/THIRD/FOURTH"418 ;;><XNAME>419 ;;>>?$$XNAME^GPLXPATH("<FOURTH>DATA1</FOURTH>")="FOURTH"420 ;;>>?$$XNAME^GPLXPATH("<SIXTH ID=""SELF"" />")="SIXTH"421 ;;>>?$$XNAME^GPLXPATH("</THIRD>")="THIRD"422 ;;><INDEX>423 ;;>>>D ZLOAD^GPLUNIT("ZTMP","GPLXPATH")424 ;;>>>D ZTEST^GPLUNIT(.ZTMP,"INITXML")425 ;;>>>D INDEX^GPLXPATH("GXML")426 ;;>>?GXML("//FIRST/SECOND")="2^12"427 ;;>>?GXML("//FIRST/SECOND/THIRD")="3^9"428 ;;>>?GXML("//FIRST/SECOND/THIRD/FIFTH")="5^7"429 ;;>>?GXML("//FIRST/SECOND/THIRD/FOURTH")="4^4"430 ;;>>?GXML("//FIRST/SECOND/THIRD/SIXTH")="8^8"431 ;;>>?GXML("//FIRST/SECOND")="2^12"432 ;;>>?GXML("//FIRST")="1^13"433 ;;><INDEX2>434 ;;>>>D ZTEST^GPLXPATH("INITXML2")435 ;;>>>D INDEX^GPLXPATH("GXML")436 ;;>>?GXML("//FIRST/SECOND")="2^12"437 ;;>>?GXML("//FIRST/SECOND/_SECOND")="9^11"438 ;;>>?GXML("//FIRST/SECOND/_SECOND/FOURTH")="10^10"439 ;;>>?GXML("//FIRST/SECOND/THIRD")="3^8"440 ;;>>?GXML("//FIRST/SECOND/THIRD/FOURTH")="4^7"441 ;;>>?GXML("//FIRST")="1^13"442 ;;><MISSING>443 ;;>>>D ZTEST^GPLXPATH("INITXML")444 ;;>>>S OUTARY="^TMP($J,""MISSINGTEST"")"445 ;;>>>D MISSING^GPLXPATH("GXML",OUTARY)446 ;;>>?@OUTARY@(1)="DATA1"447 ;;>>?@OUTARY@(2)="DATA2"448 ;;><MAP>449 ;;>>>D ZTEST^GPLXPATH("INITXML")450 ;;>>>S MAPARY="^TMP($J,""MAPVALUES"")"451 ;;>>>S OUTARY="^TMP($J,""MAPTEST"")"452 ;;>>>S @MAPARY@("DATA2")="VALUE2"453 ;;>>>D MAP^GPLXPATH("GXML",MAPARY,OUTARY)454 ;;>>?@OUTARY@(6)="VALUE2"455 ;;><QUEUE>456 ;;>>>D QUEUE^GPLXPATH("BTLIST","GXML",2,3)457 ;;>>>D QUEUE^GPLXPATH("BTLIST","GXML",4,5)458 ;;>>?$P(BTLIST(2),";",2)=4459 ;;><BUILD>460 ;;>>>D ZTEST^GPLXPATH("INITXML")461 ;;>>>D QUERY^GPLXPATH("GXML","//FIRST/SECOND/THIRD/FOURTH","G2")462 ;;>>>D ZTEST^GPLXPATH("QUEUE")463 ;;>>>D BUILD^GPLXPATH("BTLIST","G3")464 ;;><CP>465 ;;>>>D ZTEST^GPLXPATH("INITXML")466 ;;>>>D CP^GPLXPATH("GXML","G2")467 ;;>>?G2(0)=13468 ;;><QOPEN>469 ;;>>>K G2,GBL470 ;;>>>D ZTEST^GPLXPATH("INITXML")471 ;;>>>D QOPEN^GPLXPATH("GBL","GXML")472 ;;>>?$P(GBL(1),";",3)=12473 ;;>>>D BUILD^GPLXPATH("GBL","G2")474 ;;>>?G2(G2(0))="</SECOND>"475 ;;><QOPEN2>476 ;;>>>K G2,GBL477 ;;>>>D ZTEST^GPLXPATH("INITXML")478 ;;>>>D QOPEN^GPLXPATH("GBL","GXML","//FIRST/SECOND")479 ;;>>?$P(GBL(1),";",3)=11480 ;;>>>D BUILD^GPLXPATH("GBL","G2")481 ;;>>?G2(G2(0))="</SECOND>"482 ;;><QCLOSE>483 ;;>>>K G2,GBL484 ;;>>>D ZTEST^GPLXPATH("INITXML")485 ;;>>>D QCLOSE^GPLXPATH("GBL","GXML")486 ;;>>?$P(GBL(1),";",3)=13487 ;;>>>D BUILD^GPLXPATH("GBL","G2")488 ;;>>?G2(G2(0))="</FIRST>"489 ;;><QCLOSE2>490 ;;>>>K G2,GBL491 ;;>>>D ZTEST^GPLXPATH("INITXML")492 ;;>>>D QCLOSE^GPLXPATH("GBL","GXML","//FIRST/SECOND/THIRD")493 ;;>>?$P(GBL(1),";",3)=13494 ;;>>>D BUILD^GPLXPATH("GBL","G2")495 ;;>>?G2(G2(0))="</FIRST>"496 ;;>>?G2(1)="</THIRD>"497 ;;><INSERT>498 ;;>>>K G2,GBL,G3,G4499 ;;>>>D ZTEST^GPLXPATH("INITXML")500 ;;>>>D QUERY^GPLXPATH("GXML","//FIRST/SECOND/THIRD/FIFTH","G2")501 ;;>>>D INSERT^GPLXPATH("GXML","G2","//FIRST/SECOND/THIRD")502 ;;>>>D INSERT^GPLXPATH("G3","G2","//")503 ;;>>?G2(1)=GXML(9)504 ;;><REPLACE>505 ;;>>>K G2,GBL,G3506 ;;>>>D ZTEST^GPLXPATH("INITXML")507 ;;>>>D QUERY^GPLXPATH("GXML","//FIRST/SECOND/THIRD/FIFTH","G2")508 ;;>>>D REPLACE^GPLXPATH("GXML","G2","//FIRST/SECOND")509 ;;>>?GXML(3)="<FIFTH>"510 ;;><INSINNER>511 ;;>>>K GXML,G2,GBL,G3512 ;;>>>D ZTEST^GPLXPATH("INITXML")513 ;;>>>D QUERY^GPLXPATH("GXML","//FIRST/SECOND/THIRD","G2")514 ;;>>>D INSINNER^GPLXPATH("GXML","G2","//FIRST/SECOND/THIRD")515 ;;>>?GXML(10)="<FIFTH>"516 ;;><INSINNER2>517 ;;>>>K GXML,G2,GBL,G3518 ;;>>>D ZTEST^GPLXPATH("INITXML")519 ;;>>>D QUERY^GPLXPATH("GXML","//FIRST/SECOND/THIRD","G2")520 ;;>>>D INSINNER^GPLXPATH("G2","G2")521 ;;>>?G2(8)="<FIFTH>"522 ;;></TEST>366 ;;><TEST> 367 ;;><INIT> 368 ;;>>>K GPL S GPL="" 369 ;;>>>D PUSH^GPLXPATH("GPL","FIRST") 370 ;;>>>D PUSH^GPLXPATH("GPL","SECOND") 371 ;;>>>D PUSH^GPLXPATH("GPL","THIRD") 372 ;;>>>D PUSH^GPLXPATH("GPL","FOURTH") 373 ;;>>?GPL(0)=4 374 ;;><INITXML> 375 ;;>>>K GXML S GXML="" 376 ;;>>>D PUSH^GPLXPATH("GXML","<FIRST>") 377 ;;>>>D PUSH^GPLXPATH("GXML","<SECOND>") 378 ;;>>>D PUSH^GPLXPATH("GXML","<THIRD>") 379 ;;>>>D PUSH^GPLXPATH("GXML","<FOURTH>@@DATA1@@</FOURTH>") 380 ;;>>>D PUSH^GPLXPATH("GXML","<FIFTH>") 381 ;;>>>D PUSH^GPLXPATH("GXML","@@DATA2@@") 382 ;;>>>D PUSH^GPLXPATH("GXML","</FIFTH>") 383 ;;>>>D PUSH^GPLXPATH("GXML","<SIXTH ID=""SELF"" />") 384 ;;>>>D PUSH^GPLXPATH("GXML","</THIRD>") 385 ;;>>>D PUSH^GPLXPATH("GXML","<SECOND>") 386 ;;>>>D PUSH^GPLXPATH("GXML","</SECOND>") 387 ;;>>>D PUSH^GPLXPATH("GXML","</SECOND>") 388 ;;>>>D PUSH^GPLXPATH("GXML","</FIRST>") 389 ;;><INITXML2> 390 ;;>>>K GXML S GXML="" 391 ;;>>>D PUSH^GPLXPATH("GXML","<FIRST>") 392 ;;>>>D PUSH^GPLXPATH("GXML","<SECOND>") 393 ;;>>>D PUSH^GPLXPATH("GXML","<THIRD>") 394 ;;>>>D PUSH^GPLXPATH("GXML","<FOURTH>DATA1</FOURTH>") 395 ;;>>>D PUSH^GPLXPATH("GXML","<FOURTH>") 396 ;;>>>D PUSH^GPLXPATH("GXML","DATA2") 397 ;;>>>D PUSH^GPLXPATH("GXML","</FOURTH>") 398 ;;>>>D PUSH^GPLXPATH("GXML","</THIRD>") 399 ;;>>>D PUSH^GPLXPATH("GXML","<_SECOND>") 400 ;;>>>D PUSH^GPLXPATH("GXML","<FOURTH>DATA3</FOURTH>") 401 ;;>>>D PUSH^GPLXPATH("GXML","</_SECOND>") 402 ;;>>>D PUSH^GPLXPATH("GXML","</SECOND>") 403 ;;>>>D PUSH^GPLXPATH("GXML","</FIRST>") 404 ;;><PUSHPOP> 405 ;;>>>D ZLOAD^GPLUNIT("ZTMP","GPLXPATH") 406 ;;>>>D ZTEST^GPLUNIT(.ZTMP,"INIT") 407 ;;>>?GPL(GPL(0))="FOURTH" 408 ;;>>>D POP^GPLXPATH("GPL",.GX) 409 ;;>>?GX="FOURTH" 410 ;;>>?GPL(GPL(0))="THIRD" 411 ;;>>>D POP^GPLXPATH("GPL",.GX) 412 ;;>>?GX="THIRD" 413 ;;>>?GPL(GPL(0))="SECOND" 414 ;;><MKMDX> 415 ;;>>>D ZLOAD^GPLUNIT("ZTMP","GPLXPATH") 416 ;;>>>D ZTEST^GPLUNIT(.ZTMP,"INIT") 417 ;;>>>S GX="" 418 ;;>>>D MKMDX^GPLXPATH("GPL",.GX) 419 ;;>>?GX="//FIRST/SECOND/THIRD/FOURTH" 420 ;;><XNAME> 421 ;;>>?$$XNAME^GPLXPATH("<FOURTH>DATA1</FOURTH>")="FOURTH" 422 ;;>>?$$XNAME^GPLXPATH("<SIXTH ID=""SELF"" />")="SIXTH" 423 ;;>>?$$XNAME^GPLXPATH("</THIRD>")="THIRD" 424 ;;><INDEX> 425 ;;>>>D ZLOAD^GPLUNIT("ZTMP","GPLXPATH") 426 ;;>>>D ZTEST^GPLUNIT(.ZTMP,"INITXML") 427 ;;>>>D INDEX^GPLXPATH("GXML") 428 ;;>>?GXML("//FIRST/SECOND")="2^12" 429 ;;>>?GXML("//FIRST/SECOND/THIRD")="3^9" 430 ;;>>?GXML("//FIRST/SECOND/THIRD/FIFTH")="5^7" 431 ;;>>?GXML("//FIRST/SECOND/THIRD/FOURTH")="4^4" 432 ;;>>?GXML("//FIRST/SECOND/THIRD/SIXTH")="8^8" 433 ;;>>?GXML("//FIRST/SECOND")="2^12" 434 ;;>>?GXML("//FIRST")="1^13" 435 ;;><INDEX2> 436 ;;>>>D ZTEST^GPLXPATH("INITXML2") 437 ;;>>>D INDEX^GPLXPATH("GXML") 438 ;;>>?GXML("//FIRST/SECOND")="2^12" 439 ;;>>?GXML("//FIRST/SECOND/_SECOND")="9^11" 440 ;;>>?GXML("//FIRST/SECOND/_SECOND/FOURTH")="10^10" 441 ;;>>?GXML("//FIRST/SECOND/THIRD")="3^8" 442 ;;>>?GXML("//FIRST/SECOND/THIRD/FOURTH")="4^7" 443 ;;>>?GXML("//FIRST")="1^13" 444 ;;><MISSING> 445 ;;>>>D ZTEST^GPLXPATH("INITXML") 446 ;;>>>S OUTARY="^TMP($J,""MISSINGTEST"")" 447 ;;>>>D MISSING^GPLXPATH("GXML",OUTARY) 448 ;;>>?@OUTARY@(1)="DATA1" 449 ;;>>?@OUTARY@(2)="DATA2" 450 ;;><MAP> 451 ;;>>>D ZTEST^GPLXPATH("INITXML") 452 ;;>>>S MAPARY="^TMP($J,""MAPVALUES"")" 453 ;;>>>S OUTARY="^TMP($J,""MAPTEST"")" 454 ;;>>>S @MAPARY@("DATA2")="VALUE2" 455 ;;>>>D MAP^GPLXPATH("GXML",MAPARY,OUTARY) 456 ;;>>?@OUTARY@(6)="VALUE2" 457 ;;><QUEUE> 458 ;;>>>D QUEUE^GPLXPATH("BTLIST","GXML",2,3) 459 ;;>>>D QUEUE^GPLXPATH("BTLIST","GXML",4,5) 460 ;;>>?$P(BTLIST(2),";",2)=4 461 ;;><BUILD> 462 ;;>>>D ZTEST^GPLXPATH("INITXML") 463 ;;>>>D QUERY^GPLXPATH("GXML","//FIRST/SECOND/THIRD/FOURTH","G2") 464 ;;>>>D ZTEST^GPLXPATH("QUEUE") 465 ;;>>>D BUILD^GPLXPATH("BTLIST","G3") 466 ;;><CP> 467 ;;>>>D ZTEST^GPLXPATH("INITXML") 468 ;;>>>D CP^GPLXPATH("GXML","G2") 469 ;;>>?G2(0)=13 470 ;;><QOPEN> 471 ;;>>>K G2,GBL 472 ;;>>>D ZTEST^GPLXPATH("INITXML") 473 ;;>>>D QOPEN^GPLXPATH("GBL","GXML") 474 ;;>>?$P(GBL(1),";",3)=12 475 ;;>>>D BUILD^GPLXPATH("GBL","G2") 476 ;;>>?G2(G2(0))="</SECOND>" 477 ;;><QOPEN2> 478 ;;>>>K G2,GBL 479 ;;>>>D ZTEST^GPLXPATH("INITXML") 480 ;;>>>D QOPEN^GPLXPATH("GBL","GXML","//FIRST/SECOND") 481 ;;>>?$P(GBL(1),";",3)=11 482 ;;>>>D BUILD^GPLXPATH("GBL","G2") 483 ;;>>?G2(G2(0))="</SECOND>" 484 ;;><QCLOSE> 485 ;;>>>K G2,GBL 486 ;;>>>D ZTEST^GPLXPATH("INITXML") 487 ;;>>>D QCLOSE^GPLXPATH("GBL","GXML") 488 ;;>>?$P(GBL(1),";",3)=13 489 ;;>>>D BUILD^GPLXPATH("GBL","G2") 490 ;;>>?G2(G2(0))="</FIRST>" 491 ;;><QCLOSE2> 492 ;;>>>K G2,GBL 493 ;;>>>D ZTEST^GPLXPATH("INITXML") 494 ;;>>>D QCLOSE^GPLXPATH("GBL","GXML","//FIRST/SECOND/THIRD") 495 ;;>>?$P(GBL(1),";",3)=13 496 ;;>>>D BUILD^GPLXPATH("GBL","G2") 497 ;;>>?G2(G2(0))="</FIRST>" 498 ;;>>?G2(1)="</THIRD>" 499 ;;><INSERT> 500 ;;>>>K G2,GBL,G3,G4 501 ;;>>>D ZTEST^GPLXPATH("INITXML") 502 ;;>>>D QUERY^GPLXPATH("GXML","//FIRST/SECOND/THIRD/FIFTH","G2") 503 ;;>>>D INSERT^GPLXPATH("GXML","G2","//FIRST/SECOND/THIRD") 504 ;;>>>D INSERT^GPLXPATH("G3","G2","//") 505 ;;>>?G2(1)=GXML(9) 506 ;;><REPLACE> 507 ;;>>>K G2,GBL,G3 508 ;;>>>D ZTEST^GPLXPATH("INITXML") 509 ;;>>>D QUERY^GPLXPATH("GXML","//FIRST/SECOND/THIRD/FIFTH","G2") 510 ;;>>>D REPLACE^GPLXPATH("GXML","G2","//FIRST/SECOND") 511 ;;>>?GXML(3)="<FIFTH>" 512 ;;><INSINNER> 513 ;;>>>K GXML,G2,GBL,G3 514 ;;>>>D ZTEST^GPLXPATH("INITXML") 515 ;;>>>D QUERY^GPLXPATH("GXML","//FIRST/SECOND/THIRD","G2") 516 ;;>>>D INSINNER^GPLXPATH("GXML","G2","//FIRST/SECOND/THIRD") 517 ;;>>?GXML(10)="<FIFTH>" 518 ;;><INSINNER2> 519 ;;>>>K GXML,G2,GBL,G3 520 ;;>>>D ZTEST^GPLXPATH("INITXML") 521 ;;>>>D QUERY^GPLXPATH("GXML","//FIRST/SECOND/THIRD","G2") 522 ;;>>>D INSINNER^GPLXPATH("G2","G2") 523 ;;>>?G2(8)="<FIFTH>" 524 ;;></TEST>
Note:
See TracChangeset
for help on using the changeset viewer.