[613] | 1 | PXRMEXU3 ; SLC/PKR - Reminder exchange XML utilities, #3. ;12/22/2004
|
---|
| 2 | ;;2.0;CLINICAL REMINDERS;;Feb 04, 2005
|
---|
| 3 | ;===========================================
|
---|
| 4 | DESC(XMLSRC,DESC) ;Find the description in the XML source and load it
|
---|
| 5 | ;into DESC.
|
---|
| 6 | N DFOUND,DONE,IND,JND,SAVE,TAG,XMLLINE
|
---|
| 7 | S (DFOUND,DONE,JND,SAVE)=0
|
---|
| 8 | F IND=1:1 Q:DONE D
|
---|
| 9 | . S XMLLINE=@XMLSRC@(IND,0)
|
---|
| 10 | . I 'DFOUND S TAG=$$GETTAG(XMLLINE)
|
---|
| 11 | . I TAG="<DESCRIPTION>" S DFOUND=1,TAG=""
|
---|
| 12 | . I DFOUND,'SAVE,XMLLINE["<![CDATA[" S SAVE=1 Q
|
---|
| 13 | . I SAVE,XMLLINE["]]>" S SAVE=0
|
---|
| 14 | . I 'SAVE,XMLLINE["</DESCRIPTION>" S DONE=1 Q
|
---|
| 15 | . I SAVE S JND=JND+1,DESC(1,JND,0)=XMLLINE
|
---|
| 16 | S DESC(1,0)=U_U_U_JND
|
---|
| 17 | Q
|
---|
| 18 | ;
|
---|
| 19 | ;===========================================
|
---|
| 20 | FROMXML(TEXT) ;If text contains any of the XML predefined entity references
|
---|
| 21 | ;convert them to the standard characters.
|
---|
| 22 | S TEXT=$$STRREP^PXRMUTIL(TEXT,"&","&")
|
---|
| 23 | S TEXT=$$STRREP^PXRMUTIL(TEXT,"<","<")
|
---|
| 24 | S TEXT=$$STRREP^PXRMUTIL(TEXT,">",">")
|
---|
| 25 | S TEXT=$$STRREP^PXRMUTIL(TEXT,""","""")
|
---|
| 26 | S TEXT=$$STRREP^PXRMUTIL(TEXT,"'","'")
|
---|
| 27 | Q TEXT
|
---|
| 28 | ;
|
---|
| 29 | ;===========================================
|
---|
| 30 | GETTAG(XMLLINE) ;Return the XML tag.
|
---|
| 31 | N END,START,VALUE
|
---|
| 32 | S START=$F(XMLLINE,"<",1)-1
|
---|
| 33 | S END=$F(XMLLINE,">",START)-1
|
---|
| 34 | S VALUE=$E(XMLLINE,START,END)
|
---|
| 35 | Q VALUE
|
---|
| 36 | ;
|
---|
| 37 | ;===========================================
|
---|
| 38 | GETTAGV(XMLLINE,TAG,FROMXML) ;Return the value associated with the XML tag.
|
---|
| 39 | N END,ENDTAG,START,TAGL,VALUE
|
---|
| 40 | S TAGL=$L(TAG)
|
---|
| 41 | S ENDTAG="</"_$E(TAG,2,TAGL)
|
---|
| 42 | S START=$F(XMLLINE,TAG,1)
|
---|
| 43 | S END=$F(XMLLINE,ENDTAG,START)-(TAGL+2)
|
---|
| 44 | S VALUE=$E(XMLLINE,START,END)
|
---|
| 45 | I $G(FROMXML) S VALUE=$$FROMXML(VALUE)
|
---|
| 46 | Q VALUE
|
---|
| 47 | ;
|
---|
| 48 | ;===========================================
|
---|
| 49 | GETATTR(XMLLINE,ATTR) ;Return the value of attribute ATTR from the XML line
|
---|
| 50 | ;XMLLINE
|
---|
| 51 | N END,START,VALUE
|
---|
| 52 | S ATTR=ATTR_"="""
|
---|
| 53 | S START=$F(XMLLINE,ATTR,1)
|
---|
| 54 | S END=$F(XMLLINE,"""",START)-2
|
---|
| 55 | S VALUE=$E(XMLLINE,START,END)
|
---|
| 56 | Q VALUE
|
---|
| 57 | ;
|
---|
| 58 | ;===========================================
|
---|
| 59 | KEYWORD(XMLSRC,KEYWORD) ;Find the keywords in the XML source and load it
|
---|
| 60 | ;into KEYWORD.
|
---|
| 61 | N DONE,IND,JND,TAG,XMLLINE
|
---|
| 62 | S (DONE,JND)=0
|
---|
| 63 | F IND=1:1 Q:DONE D
|
---|
| 64 | . S XMLLINE=@XMLSRC@(IND,0)
|
---|
| 65 | . S TAG=$$GETTAG(XMLLINE)
|
---|
| 66 | . I TAG="<KEYWORD>" D Q
|
---|
| 67 | .. S JND=JND+1
|
---|
| 68 | .. S KEYWORD(1,JND,0)=$$GETTAGV(XMLLINE,TAG,1)
|
---|
| 69 | . I TAG="</KEYWORDS>" S DONE=1 Q
|
---|
| 70 | S KEYWORD(1,0)=U_U_U_JND
|
---|
| 71 | Q
|
---|
| 72 | ;
|
---|
| 73 | ;===========================================
|
---|
| 74 | TOXML(TEXT) ;If text contains any of the XML markup characters convert
|
---|
| 75 | ;them to the predefined entity reference.
|
---|
| 76 | S TEXT=$$STRREP^PXRMUTIL(TEXT,"&","&")
|
---|
| 77 | S TEXT=$$STRREP^PXRMUTIL(TEXT,"<","<")
|
---|
| 78 | S TEXT=$$STRREP^PXRMUTIL(TEXT,">",">")
|
---|
| 79 | S TEXT=$$STRREP^PXRMUTIL(TEXT,"""",""")
|
---|
| 80 | S TEXT=$$STRREP^PXRMUTIL(TEXT,"'","'")
|
---|
| 81 | Q TEXT
|
---|
| 82 | ;
|
---|