features for eRx template processing
This commit is contained in:
parent
8ad5d55041
commit
6383bcf232
31
p/C0CXPATH.m
31
p/C0CXPATH.m
|
@ -199,7 +199,10 @@ ZXVAL(WHAT,VAL)
|
|||
D PUSH(OUTXML,"<"_WHAT_">"_VAL_"</"_WHAT_">")
|
||||
Q
|
||||
;
|
||||
INDEX(IZXML,VDX,NOINX) ; parse the XML in IZXML and produce an XPATH index
|
||||
INDEX(IZXML,VDX,NOINX,TEMPLATE) ; parse XML in IZXML and produce an XPATH index
|
||||
; GPL 7/14/09 OPTIONALLY GENERATE AN XML TEMPLATE IF PASSED BY NAME
|
||||
; TEMPLATE IS IDENTICAL TO THE PARSED XML LINE BY LINE
|
||||
; EXCEPT THAT DATA VALUES ARE REPLACED WITH @@XPATH@@ FOR THE XPATH OF THE TAG
|
||||
; GPL 5/24/09 AND OPTIONALLY PRODUCE THE VDX ARRAY PASSED BY NAME
|
||||
; @VDX@("XPATH")=VALUE
|
||||
; ex. @IZXML@("XPATH")=FIRSTLINE^LASTLINE
|
||||
|
@ -224,6 +227,8 @@ INDEX(IZXML,VDX,NOINX) ; parse the XML in IZXML and produce an XPATH index
|
|||
S C0CSTK(0)=0 ; INITIALIZE STACK
|
||||
F I=1:1:LCNT D ; PROCESS THE ENTIRE ARRAY
|
||||
. S LINE=@IZXML@(I)
|
||||
. I $D(TEMPLATE) D ;IF TEMPLATE IS REQUESTED
|
||||
. . S @TEMPLATE@(I)=$$CLEAN(LINE)
|
||||
. ;W LINE,!
|
||||
. S FOUND=0 ; INTIALIZED FOUND FLAG
|
||||
. I LINE?.E1"<!".E S FOUND=1 ; SKIP OVER COMMENTS
|
||||
|
@ -249,6 +254,9 @@ INDEX(IZXML,VDX,NOINX) ; parse the XML in IZXML and produce an XPATH index
|
|||
. . . . 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
|
||||
. . . . I $D(TEMPLATE) D ; IF TEMPLATE IS REQUESTED
|
||||
. . . . . S LINE=$$CLEAN(LINE) ; CLEAN OUT CONTROL CHARACTERS
|
||||
. . . . . S @TEMPLATE@(I)=$P(LINE,">",1)_">@@"_MDX_"@@</"_$P(LINE,"</",2)
|
||||
. . . 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
|
||||
|
@ -279,6 +287,14 @@ INDEX(IZXML,VDX,NOINX) ; parse the XML in IZXML and produce an XPATH index
|
|||
I NOINX K @ZXML ; DELETE UNWANTED INDEX
|
||||
Q
|
||||
;
|
||||
CLEAN(STR) ; extrinsic function; returns string
|
||||
;; Removes all non printable characters from a string.
|
||||
;; STR by Value
|
||||
N TR,I
|
||||
F I=0:1:31 S TR=$G(TR)_$C(I)
|
||||
S TR=TR_$C(127)
|
||||
QUIT $TR(STR,TR)
|
||||
;
|
||||
QUERY(IARY,XPATH,OARY) ; RETURNS THE XML ARRAY MATCHING THE XPATH EXPRESSION
|
||||
; XPATH IS OF THE FORM "//FIRST/SECOND/THIRD"
|
||||
; IARY AND OARY ARE PASSED BY NAME
|
||||
|
@ -492,13 +508,18 @@ MISSING(IXML,OARY) ; SEARTH THROUGH INXLM AND PUT ANY @@X@@ VARS IN OARY
|
|||
. . Q
|
||||
Q
|
||||
;
|
||||
MAP(IXML,INARY,OXML) ; SUBSTITUTE MULTIPLE @@X@@ VARS WITH VALUES IN INARY
|
||||
MAP(IXML,INARY,OXML) ; SUBSTITUTE MULTIPLE @@X@@ VARS WITH VALUES IN INARY
|
||||
; AND PUT THE RESULTS IN OXML
|
||||
I '$D(@IXML@(0)) W "MALFORMED XML PASSED TO MAP",! Q
|
||||
N XCNT
|
||||
I '$D(DEBUG) S DEBUG=0
|
||||
I '$D(IXML) W "MALFORMED XML PASSED TO MAP",! Q
|
||||
I '$D(@IXML@(0)) D ; INITIALIZE COUNT
|
||||
. S XCNT=$O(@IXML@(""),-1)
|
||||
E S XCNT=@IXML@(0) ;COUNT
|
||||
I $O(@INARY@(""))="" W "EMPTY ARRAY PASSED TO MAP",! Q
|
||||
N I,J,TNAM,TVAL,TSTR
|
||||
S @OXML@(0)=@IXML@(0) ; TOTAL LINES IN OUTPUT
|
||||
F I=1:1:@OXML@(0) D ; LOOP THROUGH WHOLE ARRAY
|
||||
S @OXML@(0)=XCNT ; TOTAL LINES IN OUTPUT
|
||||
F I=1:1:XCNT D ; LOOP THROUGH WHOLE ARRAY
|
||||
. S @OXML@(I)=@IXML@(I) ; COPY THE LINE TO OUTPUT
|
||||
. I @OXML@(I)?.E1"@@".E D ; IS THERE A VARIABLE HERE?
|
||||
. . S TSTR=$P(@IXML@(I),"@@",1) ; INIT TO PART BEFORE VARS
|
||||
|
|
Loading…
Reference in New Issue