source: ccr/trunk/p/C0CMXMLB.m@ 1674

Last change on this file since 1674 was 1586, checked in by Sam Habiel, 12 years ago

Changed license to AGPL. Some clean-up for XINDEX

  • Property svn:mergeinfo set to (toggle deleted branches)
    /ccr/branches/ohum/o-old/p/C0CMXMLB.m1290
    /ccr/branches/ohum/p/C0CMXMLB.m1291-1543
    /ccr/branches/ohum/p/p/C0CMXMLB.m1287-1289
File size: 3.4 KB
Line 
1C0CMXMLB ;;ISF/RWF - Tool to build XML ; 5/10/12 2:51pm
2 ;;1.2;CCD/CCR GENERATION UTILITIES;;Oct 30, 2012;Build 50
3 QUIT
4 ;
5 ; FOIA Routine - Public Domain
6 ;
7 ;DOC - The top level tag
8 ;DOCTYPE - Want to include a DOCTYPE node
9 ;FLAG - Set to 'G' to store the output in the global ^TMP("MXMLBLD",$J,
10START(DOC,DOCTYPE,FLAG,NO1ST) ;Call this once at the begining.
11 K ^TMP("MXMLBLD",$J)
12 S ^TMP("MXMLBLD",$J,"DOC")=DOC,^TMP("MXMLBLD",$J,"STK")=0
13 I $G(FLAG)["G" S ^TMP("MXMLBLD",$J,"CNT")=1
14 I $G(NO1ST)'=1 D OUTPUT($$XMLHDR)
15 D:$L($G(DOCTYPE)) OUTPUT("<!DOCTYPE "_DOCTYPE_">") D OUTPUT("<"_DOC_">")
16 Q
17 ;
18END ;Call this once to close out the document
19 D OUTPUT("</"_$G(^TMP("MXMLBLD",$J,"DOC"))_">")
20 I '$G(^TMP("MXMLBLD",$J,"CNT")) K ^TMP("MXMLBLD",$J)
21 K ^TMP("MXMLBLD",$J,"DOC"),^("CNT"),^("STK")
22 Q
23 ;
24ITEM(INDENT,TAG,ATT,VALUE) ;Output a Item
25 N I,X
26 S ATT=$G(ATT)
27 I '$D(VALUE) D OUTPUT($$BLS($G(INDENT))_"<"_TAG_$$ATT(.ATT)_" />") Q
28 D OUTPUT($$BLS($G(INDENT))_"<"_TAG_$$ATT(.ATT)_">"_$$CHARCHK(VALUE)_"</"_TAG_">")
29 Q
30 ;DOITEM is a callback to output the lower level.
31MULTI(INDENT,TAG,ATT,DOITEM) ;Output a Multipule
32 N I,X,S
33 S ATT=$G(ATT)
34 D PUSH($G(INDENT),TAG,.ATT)
35 D @DOITEM
36 D POP
37 Q
38 ;
39ATT(ATT) ;Output a string of attributes
40 I $D(ATT)<9 Q ""
41 N I,S,V
42 S S="",I=""
43 F S I=$O(ATT(I)) Q:I="" S S=S_" "_I_"="_$$Q(ATT(I))
44 Q S
45 ;
46Q(X) ;Add Quotes - Changed by gpl to use single instead of double quotes 6/11
47 ;I X'[$C(34) Q $C(34)_X_$C(34)
48 I X'[$C(39) Q $C(39)_X_$C(39)
49 ;N Q,Y,I,Z S Q=$C(34),(Y,Z)=""
50 N Q,Y,I,Z S Q=$C(39),(Y,Z)=""
51 F I=1:1:$L(X,Q)-1 S Y=Y_$P(X,Q,I)_Q_Q
52 S Y=Y_$P(X,Q,$L(X,Q))
53 ;Q $C(34)_Y_$C(34)
54 Q $C(39)_Y_$C(39)
55 ;
56XMLHDR() ; -- provides current XML standard header
57 Q "<?xml version=""1.0"" encoding=""utf-8"" ?>"
58 ;
59OUTPUT(S) ;Output
60 N C S C=$G(^TMP("MXMLBLD",$J,"CNT"))
61 I C S ^TMP("MXMLBLD",$J,C)=S,^TMP("MXMLBLD",$J,"CNT")=C+1 Q
62 W S,!
63 Q
64 ;
65CHARCHK(STR) ; -- replace xml character limits with entities
66 N A,I,X,Y,Z,NEWSTR
67 S (Y,Z)=""
68 ;IF STR["&" SET NEWSTR=STR DO SET STR=Y_Z
69 ;. FOR X=1:1 SET Y=Y_$PIECE(NEWSTR,"&",X)_"&amp;",Z=$PIECE(STR,"&",X+1,999) QUIT:Z'["&"
70 I STR["&" F I=1:1:$L(STR,"&")-1 S STR=$P(STR,"&",1,I)_"&amp;"_$P(STR,"&",I+1,999)
71 I STR["<" F S STR=$PIECE(STR,"<",1)_"&lt;"_$PIECE(STR,"<",2,99) Q:STR'["<"
72 I STR[">" F S STR=$PIECE(STR,">",1)_"&gt;"_$PIECE(STR,">",2,99) Q:STR'[">"
73 I STR["'" F S STR=$PIECE(STR,"'",1)_"&apos;"_$PIECE(STR,"'",2,99) Q:STR'["'"
74 I STR["""" F S STR=$PIECE(STR,"""",1)_"&quot;"_$PIECE(STR,"""",2,99) Q:STR'[""""
75 ;
76 S STR=$TR(STR,$C(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31))
77 QUIT STR
78 ;
79COMMENT(VAL) ;Add Comments
80 N I,L
81 ;I $D($G(VAL))=1 D OUTPUT("<!-- "_ATT_" -->") Q
82 I $D(VAL) D OUTPUT("<!-- "_ATT_" -->") Q ;CHANGED BY GPL FOR GTM
83 S I="",L="<!--"
84 F S I=$O(ATT(I)) Q:I="" D OUTPUT(L_ATT(I)) S L=""
85 D OUTPUT("-->")
86 Q
87 ;
88PUSH(INDENT,TAG,ATT) ;Write a TAG and save.
89 N CNT
90 S ATT=$G(ATT)
91 D OUTPUT($$BLS($G(INDENT))_"<"_TAG_$$ATT(.ATT)_">")
92 S CNT=$G(^TMP("MXMLBLD",$J,"STK"))+1,^TMP("MXMLBLD",$J,"STK")=CNT,^TMP("MXMLBLD",$J,"STK",CNT)=INDENT_"^"_TAG
93 Q
94 ;
95POP ;Write last pushed tag and pop
96 N CNT,TAG,INDENT,X
97 S CNT=$G(^TMP("MXMLBLD",$J,"STK")),X=^TMP("MXMLBLD",$J,"STK",CNT),^TMP("MXMLBLD",$J,"STK")=CNT-1
98 S INDENT=+X,TAG=$P(X,"^",2)
99 D OUTPUT($$BLS(INDENT)_"</"_TAG_">")
100 Q
101 ;
102BLS(I) ;Return INDENT string
103 N S
104 S S="",I=$G(I) S:I>0 $P(S," ",I)=" "
105 Q S
106 ;
107INDENT() ;Renturn indent level
108 Q +$G(^TMP("MXMLBLD",$J,"STK"))
Note: See TracBrowser for help on using the repository browser.