enhancements to xpath lib for importing XML
This commit is contained in:
parent
2bc75497dc
commit
2be6b759b6
|
@ -85,8 +85,8 @@ C0CXPAT0 ; CCDCCR/GPL - XPATH TEST CASES ; 6/1/08
|
|||
;;>>?GXML("//FIRST/SECOND")="2^12"
|
||||
;;>>?GXML("//FIRST/SECOND/THIRD")="3^9"
|
||||
;;>>?GXML("//FIRST/SECOND/THIRD/FIFTH")="5^7"
|
||||
;;>>?GXML("//FIRST/SECOND/THIRD/FOURTH")="4^4"
|
||||
;;>>?GXML("//FIRST/SECOND/THIRD/SIXTH")="8^8"
|
||||
;;>>?GXML("//FIRST/SECOND/THIRD/FOURTH")="4^4^@@DATA1@@"
|
||||
;;>>?GXML("//FIRST/SECOND/THIRD/SIXTH")="8^8^"
|
||||
;;>>?GXML("//FIRST/SECOND")="2^12"
|
||||
;;>>?GXML("//FIRST")="1^13"
|
||||
;;><INDEX2>
|
||||
|
@ -94,9 +94,9 @@ C0CXPAT0 ; CCDCCR/GPL - XPATH TEST CASES ; 6/1/08
|
|||
;;>>>D INDEX^C0CXPATH("GXML")
|
||||
;;>>?GXML("//FIRST/SECOND")="2^12"
|
||||
;;>>?GXML("//FIRST/SECOND/_SECOND")="9^11"
|
||||
;;>>?GXML("//FIRST/SECOND/_SECOND/FOURTH")="10^10"
|
||||
;;>>?GXML("//FIRST/SECOND/_SECOND/FOURTH")="10^10^DATA3"
|
||||
;;>>?GXML("//FIRST/SECOND/THIRD")="3^8"
|
||||
;;>>?GXML("//FIRST/SECOND/THIRD/FOURTH")="4^7"
|
||||
;;>>?GXML("//FIRST/SECOND/THIRD/FOURTH")="4^7^DATA1"
|
||||
;;>>?GXML("//FIRST")="1^13"
|
||||
;;><MISSING>
|
||||
;;>>>D ZTEST^C0CXPATH("INITXML")
|
||||
|
|
65
p/C0CXPATH.m
65
p/C0CXPATH.m
|
@ -82,17 +82,67 @@ XNAME(ISTR) ; FUNCTION TO EXTRACT A NAME FROM AN XML FRAG
|
|||
; W "CUR2= ",CUR,!
|
||||
Q CUR
|
||||
;
|
||||
INDEX(ZXML) ; parse the XML in ZXML and produce an XPATH index
|
||||
; ex. ZXML(FIRST,SECOND,THIRD,FOURTH)=FIRSTLINE^LASTLINE
|
||||
XVAL(ISTR) ; EXTRACTS THE VALUE FROM A FRAGMENT OF XML
|
||||
; <NAME>VALUE</NAME> WILL RETURN VALUE
|
||||
N G
|
||||
S G=$P(ISTR,">",2) ;STRIP OFF <NAME>
|
||||
Q $P(G,"<",1) ; STRIP OFF </NAME> LEAVING VALUE
|
||||
;
|
||||
VDX2VDV(OUTVDV,INVDX) ; CONVERT AN VDX ARRAY TO VDV
|
||||
; VDX: @INVDX@(XPATH)=VALUE
|
||||
; VDV: @OUTVDV@(X1X2X3X4)=VALUE
|
||||
; THE VDV DATANAMES MIGHT BE MORE CONVENIENT FOR USE IN CODE
|
||||
; AN INDEX IS PROVIDED TO GO BACK TO VDX FOR CONVERSIONS
|
||||
; @VDV@("XPATH",X1X2X3X4)="XPATH"
|
||||
N ZA,ZI,ZW
|
||||
S ZI=""
|
||||
F S ZI=$O(@INVDX@(ZI)) Q:ZI="" D ;
|
||||
. S ZW=$TR(ZI,"/","") ; ELIMINATE ALL SLASHES - CAMEL CASE VARIABLE NAME
|
||||
. W ZW,!
|
||||
. S @OUTVDV@(ZW)=@INVDX@(ZI)
|
||||
. S @OUTVDV@("XPATH",ZW)=ZI
|
||||
Q
|
||||
;
|
||||
VDX2XPG(OUTXPG,INVDX) ; CONVERT AN VDX ARRAY TO XPD
|
||||
; VDX: @VDX@(XPATH)=VALUE
|
||||
; XPG: @(VDX(X1,X2,X3,X4))@=VALUE
|
||||
; THIS IS A STEP TOWARD GENERATING XML FROM A VDX
|
||||
N ZA,ZI,ZW
|
||||
S ZI=""
|
||||
F S ZI=$O(@INVDX@(ZI)) Q:ZI="" D ;
|
||||
. S ZW=$E(ZI,3,$L(ZI)) ; STRIP OFF INITIAL //
|
||||
. S ZW2=$P(ZW,"/",1)
|
||||
. F ZK=1:1:$L(ZW,"/") D PUSH("ZA",$P(ZW,"/",ZK))
|
||||
. ZWR ZA
|
||||
. S ZW2=ZA(1)
|
||||
. F ZK=2:1:ZA(0) D ;
|
||||
. . S ZW2=ZW2_""","""_ZA(ZK)
|
||||
. K ZA
|
||||
. S ZW2=""""_ZW2_""""
|
||||
. W ZW2,!
|
||||
. S ZN=OUTXPG_"("_ZW2_")"
|
||||
. S @ZN=@INVDX@(ZI)
|
||||
Q
|
||||
;
|
||||
INDEX(ZXML,VDX) ; parse the XML in ZXML and produce an XPATH index
|
||||
; GPL 5/24/09 AND OPTIONALLY PRODUCE THE VDX ARRAY PASSED BY NAME
|
||||
; @VDX@("XPATH")=VALUE
|
||||
; ex. @ZXML@("XPATH")=FIRSTLINE^LASTLINE
|
||||
; WHERE FIRSTLINE AND LASTLINE ARE THE BEGINNING AND ENDING OF THE
|
||||
; XML SECTION
|
||||
; ZXML IS PASSED BY NAME
|
||||
N I,LINE,FIRST,LAST,CUR,TMP,MDX,FOUND
|
||||
N I,LINE,FIRST,LAST,CUR,TMP,MDX,FOUND,CURVAL,DVDX,LCNT
|
||||
N C0CSTK ; LEAVE OUT FOR DEBUGGING
|
||||
I '$D(@ZXML@(0)) D ; NO XML PASSED
|
||||
I '$D(@ZXML@(0)) D ; IF COUNT NOT IN NODE 0 COUNT THEM
|
||||
. S I="",LCNT=0
|
||||
. F S I=$O(@ZXML@(I)) Q:I="" S LCNT=LCNT+1
|
||||
E S LCNT=@ZXML@(0) ; LINE COUNT PASSED IN ARRAY
|
||||
I LCNT=0 D Q ; NO XML PASSED
|
||||
. W "ERROR IN XML FILE",!
|
||||
S DVDX=0 ; DEFAULT DO NOT PRODUCE VDX INDEX
|
||||
I $D(VDX) S DVDX=1 ; IF NAME PASSED, DO VDX
|
||||
S C0CSTK(0)=0 ; INITIALIZE STACK
|
||||
F I=1:1:@ZXML@(0) D ; PROCESS THE ENTIRE ARRAY
|
||||
F I=1:1:LCNT D ; PROCESS THE ENTIRE ARRAY
|
||||
. S LINE=@ZXML@(I)
|
||||
. ;W LINE,!
|
||||
. S FOUND=0 ; INTIALIZED FOUND FLAG
|
||||
|
@ -111,6 +161,9 @@ INDEX(ZXML) ; parse the XML in ZXML and produce an XPATH index
|
|||
. . . . S $P(@ZXML@(MDX),"^",2)=I ; UPDATE LAST LINE NUMBER
|
||||
. . . I '$D(@ZXML@(MDX)) D ; NOT IN THE INDEX, NOT A MULTIPLE
|
||||
. . . . S @ZXML@(MDX)=I_"^"_I ; ADD INDEX ENTRY-FIRST AND LAST
|
||||
. . . . S CURVAL=$$XVAL(LINE) ; VALUE
|
||||
. . . . S $P(@ZXML@(MDX),"^",3)=CURVAL ; THIRD PIECE
|
||||
. . . . I DVDX S @VDX@(MDX)=CURVAL ; FILL IN VDX ARRAY IF REQUESTED
|
||||
. . . D POP("C0CSTK",.TMP) ; REMOVE FROM STACK
|
||||
. I FOUND'=1 D ; THE LINE DOESN'T CONTAIN THE START AND END
|
||||
. . I LINE?.E1"</"1.E D ; LINE CONTAINS END OF A SECTION
|
||||
|
@ -137,7 +190,7 @@ INDEX(ZXML) ; parse the XML in ZXML and produce an XPATH index
|
|||
. . . I '$D(@ZXML@(MDX)) D ; NOT IN THE INDEX, NOT A MULTIPLE
|
||||
. . . . S @ZXML@(MDX)=I_"^" ; INSERT INTO THE INDEX
|
||||
S @ZXML@("INDEXED")=""
|
||||
S @ZXML@("//")="1^"_@ZXML@(0) ; ROOT XPATH
|
||||
S @ZXML@("//")="1^"_LCNT ; ROOT XPATH
|
||||
Q
|
||||
;
|
||||
QUERY(IARY,XPATH,OARY) ; RETURNS THE XML ARRAY MATCHING THE XPATH EXPRESSION
|
||||
|
|
Loading…
Reference in New Issue