source: FOIAVistA/trunk/r/XML_PARSER-MXML/MXMLDOM.m@ 1586

Last change on this file since 1586 was 628, checked in by George Lilly, 15 years ago

initial load of FOIAVistA 6/30/08 version

File size: 2.8 KB
Line 
1MXMLDOM ;SAIC/DKM - XML Parser - DOM model ;02/27/2002 13:24
2 ;;7.3;TOOLKIT;**58**;Apr 25, 1995
3 ;=================================================================
4 ; This acts as an intermediate client between the event-based XML
5 ; parser and a client requiring an in-memory document model.
6EN(DOC,OPTION) ;
7 N CBK,SUCCESS,LEVEL,NODE,HANDLE
8 K ^TMP("MXMLERR",$J)
9 L +^TMP("MXMLDOM",$J):5
10 E Q 0
11 S HANDLE=$O(^TMP("MXMLDOM",$J,""),-1)+1,^(HANDLE)=""
12 L -^TMP("MXMLDOM",$J)
13 S CBK("STARTELEMENT")="STARTELE^MXMLDOM"
14 S CBK("ENDELEMENT")="ENDELE^MXMLDOM"
15 S CBK("COMMENT")="COMMENT^MXMLDOM"
16 S CBK("CHARACTERS")="CHAR^MXMLDOM"
17 S CBK("ENDDOCUMENT")="ENDDOC^MXMLDOM"
18 S CBK("ERROR")="ERROR^MXMLDOM"
19 S (SUCCESS,LEVEL,LEVEL(0),NODE)=0,OPTION=$G(OPTION,"V1")
20 D EN^MXMLPRSE(DOC,.CBK,OPTION)
21 D:'SUCCESS DELETE(HANDLE)
22 Q $S(SUCCESS:HANDLE,1:0)
23 ; Start element
24 ; Create new child node and push info on stack
25STARTELE(ELE,ATTR) ;
26 N PARENT
27 S PARENT=LEVEL(LEVEL),NODE=NODE+1
28 S:PARENT ^TMP("MXMLDOM",$J,HANDLE,PARENT,"C",NODE)=ELE
29 S LEVEL=LEVEL+1,LEVEL(LEVEL)=NODE,LEVEL(LEVEL,0)=ELE
30 S ^TMP("MXMLDOM",$J,HANDLE,NODE)=ELE,^(NODE,"P")=PARENT
31 M ^("A")=ATTR
32 Q
33 ; End element
34 ; Pops element stack
35ENDELE(ELE) ;
36 K LEVEL(LEVEL)
37 S LEVEL=LEVEL-1
38 Q
39 ; Comment data
40COMMENT(TXT) ;
41 D TXT("X")
42 Q
43 ; Character data
44CHAR(TXT) ;
45 D TXT("T")
46 Q
47 ; Store comment or character data
48TXT(SUB) N X,Y,Z
49 S Y=$O(^TMP("MXMLDOM",$J,HANDLE,LEVEL(LEVEL),SUB,""),-1)
50 I Y>0,($L($G(^(Y)))+$L(TXT)>200)!($G(BGN)["CDATA") S Y=Y+1 ;*rwf
51 S:'Y Y=1
52 F Z=$L(TXT,$C(10)):-1:1 Q:TXT="" D
53 .S X=$P(TXT,$C(10)),TXT=$P(TXT,$C(10),2,9999)
54 .S ^(Y)=$G(^(Y))_X
55 .S:Z>1 Y=Y+1 ;*rwf old .S:Z>1 Y=Y+1,^(Y)=""
56 Q
57 ; End of document
58ENDDOC S SUCCESS=1
59 Q
60 ;Error reporting
61ERROR(ERR) ;
62 N CNT
63 S CNT=1+$G(^TMP("MXMLERR",$J)),^($J)=CNT
64 M ^TMP("MXMLERR",$J,CNT)=ERR
65 Q
66 ;
67 ; Below are the external API calls for the interface
68 ;
69 ; Delete document instance
70DELETE(HANDLE) ;
71 K ^TMP("MXMLDOM",$J,HANDLE)
72 Q
73 ; Name of element at node
74NAME(HANDLE,NODE) ;
75 Q $G(^TMP("MXMLDOM",$J,HANDLE,NODE))
76 ; Node of next child
77CHILD(HANDLE,PARENT,CHILD) ;
78 Q +$O(^TMP("MXMLDOM",$J,HANDLE,PARENT,"C",+$G(CHILD)))
79 ; Node of next sibling
80SIBLING(HANDLE,NODE) ;
81 Q +$O(^TMP("MXMLDOM",$J,HANDLE,$$PARENT(HANDLE,NODE),"C",NODE))
82 ; Parent of node
83PARENT(HANDLE,NODE) ;
84 Q +$G(^TMP("MXMLDOM",$J,HANDLE,NODE,"P"))
85 ; Text associated with node
86TEXT(HANDLE,NODE,RTN) ;
87 D GETTXT("T")
88 Q:$Q $D(@RTN)>1
89 Q
90 ; Comment associate with node
91CMNT(HANDLE,NODE,RTN) ;
92 D GETTXT("X")
93 Q:$Q $D(@RTN)>1
94 Q
95 ; Retrieve text or comment
96GETTXT(SUB) ;
97 K @RTN
98 M @RTN=^TMP("MXMLDOM",$J,HANDLE,NODE,SUB)
99 Q
100 ; Retrieve next attribute
101ATTRIB(HANDLE,NODE,ATTR) ;
102 Q $O(^TMP("MXMLDOM",$J,HANDLE,NODE,"A",$G(ATTR)))
103 ; Retrieve attribute value
104VALUE(HANDLE,NODE,ATTR) ;
105 Q $G(^TMP("MXMLDOM",$J,HANDLE,NODE,"A",ATTR))
Note: See TracBrowser for help on using the repository browser.