PXRMEXU3 ; SLC/PKR - Reminder exchange XML utilities, #3. ;12/22/2004
;;2.0;CLINICAL REMINDERS;;Feb 04, 2005
;===========================================
DESC(XMLSRC,DESC) ;Find the description in the XML source and load it
;into DESC.
N DFOUND,DONE,IND,JND,SAVE,TAG,XMLLINE
S (DFOUND,DONE,JND,SAVE)=0
F IND=1:1 Q:DONE D
. S XMLLINE=@XMLSRC@(IND,0)
. I 'DFOUND S TAG=$$GETTAG(XMLLINE)
. I TAG="<DESCRIPTION>" S DFOUND=1,TAG=""
. I DFOUND,'SAVE,XMLLINE["<![CDATA[" S SAVE=1 Q
. I SAVE,XMLLINE["]]>" S SAVE=0
. I 'SAVE,XMLLINE["</DESCRIPTION>" S DONE=1 Q
. I SAVE S JND=JND+1,DESC(1,JND,0)=XMLLINE
S DESC(1,0)=U_U_U_JND
Q
;
;===========================================
FROMXML(TEXT) ;If text contains any of the XML predefined entity references
;convert them to the standard characters.
S TEXT=$$STRREP^PXRMUTIL(TEXT,"&","&")
S TEXT=$$STRREP^PXRMUTIL(TEXT,"<","<")
S TEXT=$$STRREP^PXRMUTIL(TEXT,">",">")
S TEXT=$$STRREP^PXRMUTIL(TEXT,""","""")
S TEXT=$$STRREP^PXRMUTIL(TEXT,"'","'")
Q TEXT
;
;===========================================
GETTAG(XMLLINE) ;Return the XML tag.
N END,START,VALUE
S START=$F(XMLLINE,"<",1)-1
S END=$F(XMLLINE,">",START)-1
S VALUE=$E(XMLLINE,START,END)
Q VALUE
;
;===========================================
GETTAGV(XMLLINE,TAG,FROMXML) ;Return the value associated with the XML tag.
N END,ENDTAG,START,TAGL,VALUE
S TAGL=$L(TAG)
S ENDTAG="</"_$E(TAG,2,TAGL)
S START=$F(XMLLINE,TAG,1)
S END=$F(XMLLINE,ENDTAG,START)-(TAGL+2)
S VALUE=$E(XMLLINE,START,END)
I $G(FROMXML) S VALUE=$$FROMXML(VALUE)
Q VALUE
;
;===========================================
GETATTR(XMLLINE,ATTR) ;Return the value of attribute ATTR from the XML line
;XMLLINE
N END,START,VALUE
S ATTR=ATTR_"="""
S START=$F(XMLLINE,ATTR,1)
S END=$F(XMLLINE,"""",START)-2
S VALUE=$E(XMLLINE,START,END)
Q VALUE
;
;===========================================
KEYWORD(XMLSRC,KEYWORD) ;Find the keywords in the XML source and load it
;into KEYWORD.
N DONE,IND,JND,TAG,XMLLINE
S (DONE,JND)=0
F IND=1:1 Q:DONE D
. S XMLLINE=@XMLSRC@(IND,0)
. S TAG=$$GETTAG(XMLLINE)
. I TAG="<KEYWORD>" D Q
.. S JND=JND+1
.. S KEYWORD(1,JND,0)=$$GETTAGV(XMLLINE,TAG,1)
. I TAG="</KEYWORDS>" S DONE=1 Q
S KEYWORD(1,0)=U_U_U_JND
Q
;
;===========================================
TOXML(TEXT) ;If text contains any of the XML markup characters convert
;them to the predefined entity reference.
S TEXT=$$STRREP^PXRMUTIL(TEXT,"&","&")
S TEXT=$$STRREP^PXRMUTIL(TEXT,"<","<")
S TEXT=$$STRREP^PXRMUTIL(TEXT,">",">")
S TEXT=$$STRREP^PXRMUTIL(TEXT,"""",""")
S TEXT=$$STRREP^PXRMUTIL(TEXT,"'","'")
Q TEXT
;
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HPXRMEXU3 2752 printed Dec 13, 2024@01:45:19 Page 2
PXRMEXU3 ; SLC/PKR - Reminder exchange XML utilities, #3. ;12/22/2004
+1 ;;2.0;CLINICAL REMINDERS;;Feb 04, 2005
+2 ;===========================================
DESC(XMLSRC,DESC) ;Find the description in the XML source and load it
+1 ;into DESC.
+2 NEW DFOUND,DONE,IND,JND,SAVE,TAG,XMLLINE
+3 SET (DFOUND,DONE,JND,SAVE)=0
+4 FOR IND=1:1
if DONE
QUIT
Begin DoDot:1
+5 SET XMLLINE=@XMLSRC@(IND,0)
+6 IF 'DFOUND
SET TAG=$$GETTAG(XMLLINE)
+7 IF TAG="<DESCRIPTION>"
SET DFOUND=1
SET TAG=""
+8 IF DFOUND
IF 'SAVE
IF XMLLINE["<![CDATA["
SET SAVE=1
QUIT
+9 IF SAVE
IF XMLLINE["]]>"
SET SAVE=0
+10 IF 'SAVE
IF XMLLINE["</DESCRIPTION>"
SET DONE=1
QUIT
+11 IF SAVE
SET JND=JND+1
SET DESC(1,JND,0)=XMLLINE
End DoDot:1
+12 SET DESC(1,0)=U_U_U_JND
+13 QUIT
+14 ;
+15 ;===========================================
FROMXML(TEXT) ;If text contains any of the XML predefined entity references
+1 ;convert them to the standard characters.
+2 SET TEXT=$$STRREP^PXRMUTIL(TEXT,"&","&")
+3 SET TEXT=$$STRREP^PXRMUTIL(TEXT,"<","<")
+4 SET TEXT=$$STRREP^PXRMUTIL(TEXT,">",">")
+5 SET TEXT=$$STRREP^PXRMUTIL(TEXT,""","""")
+6 SET TEXT=$$STRREP^PXRMUTIL(TEXT,"'","'")
+7 QUIT TEXT
+8 ;
+9 ;===========================================
GETTAG(XMLLINE) ;Return the XML tag.
+1 NEW END,START,VALUE
+2 SET START=$FIND(XMLLINE,"<",1)-1
+3 SET END=$FIND(XMLLINE,">",START)-1
+4 SET VALUE=$EXTRACT(XMLLINE,START,END)
+5 QUIT VALUE
+6 ;
+7 ;===========================================
GETTAGV(XMLLINE,TAG,FROMXML) ;Return the value associated with the XML tag.
+1 NEW END,ENDTAG,START,TAGL,VALUE
+2 SET TAGL=$LENGTH(TAG)
+3 SET ENDTAG="</"_$EXTRACT(TAG,2,TAGL)
+4 SET START=$FIND(XMLLINE,TAG,1)
+5 SET END=$FIND(XMLLINE,ENDTAG,START)-(TAGL+2)
+6 SET VALUE=$EXTRACT(XMLLINE,START,END)
+7 IF $GET(FROMXML)
SET VALUE=$$FROMXML(VALUE)
+8 QUIT VALUE
+9 ;
+10 ;===========================================
GETATTR(XMLLINE,ATTR) ;Return the value of attribute ATTR from the XML line
+1 ;XMLLINE
+2 NEW END,START,VALUE
+3 SET ATTR=ATTR_"="""
+4 SET START=$FIND(XMLLINE,ATTR,1)
+5 SET END=$FIND(XMLLINE,"""",START)-2
+6 SET VALUE=$EXTRACT(XMLLINE,START,END)
+7 QUIT VALUE
+8 ;
+9 ;===========================================
KEYWORD(XMLSRC,KEYWORD) ;Find the keywords in the XML source and load it
+1 ;into KEYWORD.
+2 NEW DONE,IND,JND,TAG,XMLLINE
+3 SET (DONE,JND)=0
+4 FOR IND=1:1
if DONE
QUIT
Begin DoDot:1
+5 SET XMLLINE=@XMLSRC@(IND,0)
+6 SET TAG=$$GETTAG(XMLLINE)
+7 IF TAG="<KEYWORD>"
Begin DoDot:2
+8 SET JND=JND+1
+9 SET KEYWORD(1,JND,0)=$$GETTAGV(XMLLINE,TAG,1)
End DoDot:2
QUIT
+10 IF TAG="</KEYWORDS>"
SET DONE=1
QUIT
End DoDot:1
+11 SET KEYWORD(1,0)=U_U_U_JND
+12 QUIT
+13 ;
+14 ;===========================================
TOXML(TEXT) ;If text contains any of the XML markup characters convert
+1 ;them to the predefined entity reference.
+2 SET TEXT=$$STRREP^PXRMUTIL(TEXT,"&","&")
+3 SET TEXT=$$STRREP^PXRMUTIL(TEXT,"<","<")
+4 SET TEXT=$$STRREP^PXRMUTIL(TEXT,">",">")
+5 SET TEXT=$$STRREP^PXRMUTIL(TEXT,"""",""")
+6 SET TEXT=$$STRREP^PXRMUTIL(TEXT,"'","'")
+7 QUIT TEXT
+8 ;