1 | C0CMXP ; GPL - MXML based XPath utilities;12/04/09 17:05
|
---|
2 | ;;0.1;C0C;nopatch;noreleasedate
|
---|
3 | ;Copyright 2009 George Lilly. Licensed under the terms of the GNU
|
---|
4 | ;General Public License See attached copy of the License.
|
---|
5 | ;
|
---|
6 | ;This program is free software; you can redistribute it and/or modify
|
---|
7 | ;it under the terms of the GNU General Public License as published by
|
---|
8 | ;the Free Software Foundation; either version 2 of the License, or
|
---|
9 | ;(at your option) any later version.
|
---|
10 | ;
|
---|
11 | ;This program is distributed in the hope that it will be useful,
|
---|
12 | ;but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | ;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
14 | ;GNU General Public License for more details.
|
---|
15 | ;
|
---|
16 | ;You should have received a copy of the GNU General Public License along
|
---|
17 | ;with this program; if not, write to the Free Software Foundation, Inc.,
|
---|
18 | ;51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
---|
19 | ;
|
---|
20 | Q
|
---|
21 | ;
|
---|
22 | INITXPF(ARY) ;INITIAL XML/XPATH FILE ARRAY
|
---|
23 | ;
|
---|
24 | S @ARY@("XML FILE NUMBER")=178.101
|
---|
25 | S @ARY@("XML SOURCE FIELD")=2.1
|
---|
26 | S @ARY@("XML TEMPLATE FIELD")=3
|
---|
27 | S @ARY@("XPATH BINDING SUBFILE")=178.1014
|
---|
28 | Q
|
---|
29 | ;
|
---|
30 | SETXPF(ARY) ; SET FILE AND FIELD VARIABLES FROM XPF ARRAY
|
---|
31 | ;
|
---|
32 | S C0CXPF=@ARY@("XML FILE NUMBER")
|
---|
33 | S C0CXFLD=@ARY@("XML SOURCE FIELD")
|
---|
34 | S C0CXTFLD=@ARY@("XML TEMPLATE FIELD")
|
---|
35 | S C0CXPBF=@ARY@("XPATH BINDING SUBFILE")
|
---|
36 | Q
|
---|
37 | ;
|
---|
38 | ADDXP(INARY,TID,FARY) ;ADD XPATH .01 FIELD TO BINDING SUBFILE OF TEMPLATE TID
|
---|
39 | I '$D(FARY) D ;
|
---|
40 | . S FARY="FARY" ; FILE ARRAY
|
---|
41 | . D INITXPF("FARY") ;IF FILE ARRAY NOT PASSED, INITIALIZE
|
---|
42 | D SETXPF(FARY) ;SET FILE VARIABLES
|
---|
43 | N C0CA,C0CB
|
---|
44 | S C0CA="" S C0CB=0
|
---|
45 | F S C0CA=$O(@INARY@(C0CA)) Q:C0CA="" D ; FOR EACH XPATH
|
---|
46 | . S C0CB=C0CB+1 ; COUNT OF XPATHS
|
---|
47 | . S C0CFDA(C0CXPBF,"?+"_C0CB_","_TID_",",.01)=C0CA
|
---|
48 | . D UPDIE ; CREATE THE BINDING SUBFILE FOR THIS XPATH
|
---|
49 | Q
|
---|
50 | ;
|
---|
51 | ADDXML(INXML,TEMPID,FARY) ;ADD XML TO A TEMPLATE ID TEMPID
|
---|
52 | ; INXML IS PASSED BY NAME
|
---|
53 | I '$D(FARY) D ;
|
---|
54 | . S FARY="FARY" ; FILE ARRAY
|
---|
55 | . D INITXPF("FARY") ;IF FILE ARRAY NOT PASSED, INITIALIZE
|
---|
56 | D SETXPF(FARY) ;SET FILE VARIABLES
|
---|
57 | D WP^DIE(C0CXPF,TEMPID_",",C0CXFLD,,INXML)
|
---|
58 | Q
|
---|
59 | ;
|
---|
60 | ADDTEMP(INXML,TEMPID,FARY) ;ADD XML TEMPLATE TO TEMPLATE RECORD TEMPID FIELD 3
|
---|
61 | ;
|
---|
62 | I '$D(FARY) D ;
|
---|
63 | . S FARY="FARY" ; FILE ARRAY
|
---|
64 | . D INITXPF("FARY") ;IF FILE ARRAY NOT PASSED, INITIALIZE
|
---|
65 | D SETXPF(FARY) ;SET FILE VARIABLES
|
---|
66 | D WP^DIE(C0CXPF,TEMPID_",",C0CXTFLD,,INXML)
|
---|
67 | Q
|
---|
68 | ;
|
---|
69 | GETXML(OUTXML,TEMPID,FARY) ;GET THE XML FROM TEMPLATE TEMPID
|
---|
70 | ;
|
---|
71 | I '$D(FARY) D ;
|
---|
72 | . S FARY="FARY" ; FILE ARRAY
|
---|
73 | . D INITXPF("FARY") ;IF FILE ARRAY NOT PASSED, INITIALIZE
|
---|
74 | D SETXPF(FARY) ;SET FILE VARIABLES
|
---|
75 | I $$GET1^DIQ(C0CXPF,TEMPID_",",C0CXFLD,,OUTXML)'=OUTXML D Q ;
|
---|
76 | . W "ERROR RETRIEVING TEMPLATE",!
|
---|
77 | Q
|
---|
78 | ;
|
---|
79 | MKTPLATE(INXML,OUTT) ;MAKE A TEMPLATE FROM INXML, RETURNED IN OUTT
|
---|
80 | ; BOTH PASSED BY NAME
|
---|
81 | ;
|
---|
82 | S C0CDOCID=$$PARSE^C0CMXML(INXML,"C0CMKT")
|
---|
83 | S C0CDOM=$NA(^TMP("MXMLDOM",$J,C0CDOCID))
|
---|
84 | N ZI S ZI=""
|
---|
85 | F S ZI=$O(@C0CDOM@(ZI)) Q:ZI="" D ; FOR EACH NODE IN THE DOM
|
---|
86 | . W !,ZI,$$TAG^C0CMXML(ZI)
|
---|
87 | Q
|
---|
88 | ;
|
---|
89 | DEMUX(OUTX,INX) ;PARSES XPATH PASSED BY VALUE IN INX TO REMOVE [x] MULTIPLES
|
---|
90 | ; RETURNS OUTX: MULTIPLE^SUBMULTIPLE^XPATH
|
---|
91 | N ZX,ZY,ZZ,ZZ1,ZMULT,ZSUB
|
---|
92 | S (ZMULT,ZSUB)=""
|
---|
93 | S ZX=$P(INX,"[",2)
|
---|
94 | I ZX'="" D ; THERE IS A [x] MULTIPLE
|
---|
95 | . S ZY=$P(INX,"[",1) ;FIRST PART OF XPATH
|
---|
96 | . S ZMULT=$P(ZX,"]",1) ; NUMBER OF THE MULTIPLE
|
---|
97 | . S ZX=ZY_$P(ZX,"]",2) ; REST OF THE XPATH
|
---|
98 | . I $P(ZX,"[",2)'="" D ; A SUB MULTIPLE EXISTS
|
---|
99 | . . S ZZ=$P(ZX,"[",1) ; FIRST PART OF XPATH
|
---|
100 | . . S ZX=$P(ZX,"[",2) ; DELETE THE [
|
---|
101 | . . S ZSUB=$P(ZX,"]",1) ; NUMBER OF THE SUBMULTIPLE
|
---|
102 | . . S ZX=ZZ_$P(ZX,"]",2) ; REST OF THE XPATH
|
---|
103 | E S ZX=INX ;NO MULTIPLE HERE
|
---|
104 | S @OUTX=ZMULT_"^"_ZSUB_"^"_ZX ;RETURN MULTIPLE^SUBMULTIPLE^XPATH
|
---|
105 | Q
|
---|
106 | ;
|
---|
107 | UPDIE ; INTERNAL ROUTINE TO CALL UPDATE^DIE AND CHECK FOR ERRORS
|
---|
108 | K ZERR
|
---|
109 | D CLEAN^DILF
|
---|
110 | D UPDATE^DIE("","C0CFDA","","ZERR")
|
---|
111 | I $D(ZERR) D ;
|
---|
112 | . W "ERROR",!
|
---|
113 | . ZWR ZERR
|
---|
114 | . B
|
---|
115 | K C0CFDA
|
---|
116 | Q
|
---|
117 | ;
|
---|