From 1dbbb222bfe03c76e8c183f07842f0203df2ebaa Mon Sep 17 00:00:00 2001 From: george Date: Wed, 9 Sep 2009 00:29:22 +0000 Subject: [PATCH] addition of multiples in XPATH generation --- p/C0CXPATH.m | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/p/C0CXPATH.m b/p/C0CXPATH.m index cf5f414..710ee30 100644 --- a/p/C0CXPATH.m +++ b/p/C0CXPATH.m @@ -225,6 +225,7 @@ INDEX(IZXML,VDX,NOINX,TEMPLATE) ; parse XML in IZXML and produce an XPATH index 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 + D MKLASD(.LKASD,IZXML) ;MAKE LOOK ASIDE BUFFER FOR MULTIPLES F I=1:1:LCNT D ; PROCESS THE ENTIRE ARRAY . S LINE=@IZXML@(I) . I $D(TEMPLATE) D ;IF TEMPLATE IS REQUESTED @@ -239,6 +240,7 @@ INDEX(IZXML,VDX,NOINX,TEMPLATE) ; parse XML in IZXML and produce an XPATH index . . . ; W "FOUND ",LINE,! . . . S FOUND=1 ; SET FOUND FLAG . . . S CUR=$$XNAME(LINE) ; EXTRACT THE NAME + . . . S CUR=CUR_$G(LKASD(CUR,I)) ; HANDLE MULTIPLES . . . D PUSH("C0CSTK",CUR) ; ADD TO THE STACK . . . D MKMDX("C0CSTK",.MDX) ; GENERATE THE M INDEX . . . ; W "MDX=",MDX,! @@ -266,6 +268,7 @@ INDEX(IZXML,VDX,NOINX,TEMPLATE) ; parse XML in IZXML and produce an XPATH index . . . D MKMDX("C0CSTK",.MDX) ; GENERATE THE M INDEX . . . S $P(@ZXML@(MDX),"^",2)=I ; UPDATE LAST LINE NUMBER . . . D POP("C0CSTK",.TMP) ; REMOVE FROM STACK + . . . S TMP=$P(TMP,"[",1) ; REMOVE [X] FROM MULTIPLE . . . I TMP'=CUR D ; MALFORMED XML, END MUST MATCH START . . . . W "MALFORMED XML ",CUR,"LINE "_I_LINE,! . . . . D PARY("C0CSTK") ; PRINT OUT THE STACK FOR DEBUGING @@ -275,11 +278,13 @@ INDEX(IZXML,VDX,NOINX,TEMPLATE) ; parse XML in IZXML and produce an XPATH index . . . ; W "FOUND ",LINE,! . . . S FOUND=1 ; SET FOUND FLAG . . . S CUR=$$XNAME(LINE) ; EXTRACT THE NAME + . . . S CUR=CUR_$G(LKASD(CUR,I)) ; HANDLE MULTIPLES . . . D PUSH("C0CSTK",CUR) ; ADD TO THE STACK . . . D MKMDX("C0CSTK",.MDX) ; GENERATE THE M INDEX . . . ; W "MDX=",MDX,! . . . I $D(@ZXML@(MDX)) D ; IN THE INDEX, IS A MULTIPLE . . . . S $P(@ZXML@(MDX),"^",2)=I ; UPDATE LAST LINE NUMBER + . . . . ;B . . . I '$D(@ZXML@(MDX)) D ; NOT IN THE INDEX, NOT A MULTIPLE . . . . S @ZXML@(MDX)=I_"^" ; INSERT INTO THE INDEX S @ZXML@("INDEXED")="" @@ -287,6 +292,32 @@ INDEX(IZXML,VDX,NOINX,TEMPLATE) ; parse XML in IZXML and produce an XPATH index I NOINX K @ZXML ; DELETE UNWANTED INDEX Q ; +MKLASD(OUTBUF,INARY) ; CREATE A LOOKASIDE BUFFER FOR MULTILPLES + ; + N ZI,ZN,ZA,ZLINE,ZLINE2,CUR,CUR2 + F ZI=1:1:LCNT-1 D ; PROCESS THE ENTIRE ARRAY + . S ZLINE=@IZXML@(ZI) + . I ZI") D ; BEGINNING OF A SECTION + . . . S CUR2=$$XNAME(ZLINE2) ; EXTRACT THE NAME + . . . I CUR=CUR2 D ; IF THIS IS A MULTIPLE + . . . . S OUTBUF(CUR,ZI+1)="" + ;ZWR OUTBUF + S ZI="" + F S ZI=$O(OUTBUF(ZI)) Q:ZI="" D ; FOR EACH KIND OF MULTIPLE + . S ZN=$O(OUTBUF(ZI,"")) ; LINE NUMBER OF SECOND MULTIPLE + . F S ZN=$O(@IZXML@(ZN),-1) Q:ZN="" I $P(@IZXML@(ZN),"<"_ZI,2)=">" Q ; + . S OUTBUF(ZI,ZN)="" + S ZA=1,ZI="",ZN="" + F S ZI=$O(OUTBUF(ZI)) Q:ZI="" D ; ADDING THE COUNT FOR THE MULIPLES [x] + . S ZN="",ZA=1 + . F S ZN=$O(OUTBUF(ZI,ZN)) Q:ZN="" D ; + . . S OUTBUF(ZI,ZN)="["_ZA_"]" + . . S ZA=ZA+1 + Q + ; CLEAN(STR) ; extrinsic function; returns string ;; Removes all non printable characters from a string. ;; STR by Value