Index: ccr/trunk/p/C0CDOM.m
===================================================================
--- ccr/trunk/p/C0CDOM.m	(revision 1203)
+++ ccr/trunk/p/C0CDOM.m	(revision 1204)
@@ -126,8 +126,9 @@
  Q
  ;
-OUTXML(ZRTN,INID)	; USES C0CMXMLB (MXMLBLD) TO OUTPUT XML FROM AN MXMLDOM
+OUTXML(ZRTN,INID,NO1ST)	; USES C0CMXMLB (MXMLBLD) TO OUTPUT XML FROM AN MXMLDOM
  ;
  S C0CDOCID=INID
- D START^C0CMXMLB($$TAG(1),,"G")
+ I '$D(NO1ST) S NO1ST=0 ; DO NOT SURPRESS THE <?xml tag generation
+ D START^C0CMXMLB($$TAG(1),,"G",NO1ST)
  D NDOUT($$FIRST(1))
  D END^C0CMXMLB ;END THE DOCUMENT
@@ -156,4 +157,12 @@
  S GN2=$NA(@GN@(1))
  W $$OUTPUT^C0CXPATH(GN2,"nhin_"_ZDFN_".xml","/home/wvehr3-09/")
+ Q
+ ;
+NARY2XML(ZGOUT,ZGIN) ; CREATE XML FROM AN NHIN ARRAY
+ ; ZGOUT AND ZGIN ARE PASSED BY NAME
+ N C0CDOCID
+ W !,ZGOUT," ",ZGIN
+ S C0CDOCID=$$DOMI(ZGIN) ; PUT IT INTO THE DOM
+ D OUTXML(ZGOUT,C0CDOCID)
  Q
  ;
@@ -217,34 +226,41 @@
  I '$D(INARY) Q 0 ; NO ARRAY PASSED
  I '$D(HANDLE) S HANDLE=$$NEWDOM() ; MAKE A NEW DOM
+ ;I PARENT="" S PARENT="root"
  I +$G(PARENT)>0 S ZPARNODE=PARENT ; WE HAVE BEEN PASSED A PARENT NODE ID
- E  I $L(PARENT)>0 D  ; TBD FIND THE PARENT IN THE DOM AND SET LEVEL
+ E  I $L($G(PARENT))>0 D  ; TBD FIND THE PARENT IN THE DOM AND SET LEVEL
  . D STARTELE^MXMLDOM(PARENT) ; INSERT THE PARENT NODE
  . S ZPARNODE=1 ;
  ; WE NOW HAVE A HANDLE AND A PARENT NODE AND LEVEL HAS BEEN SET
- D MAJOR(INARY,"",0) ; PROCESS ALL THE NODES TO BE ADDED
- I $L(PARENT)>0 D ENDELE^MXMLDOM(PARENT) ; CLOSE OUT THE PARENT NODE
- Q 1 ; SUCCESS
+ N ZEXARY
+ D EXPAND("ZEXARY",INARY) ; EXPAND THE NHIN ARRAY
+ D MAJOR("ZEXARY") ; PROCESS ALL THE NODES TO BE ADDED
+ I $L($G(PARENT))>0 D ENDELE^MXMLDOM(PARENT) ; CLOSE OUT THE PARENT NODE
+ Q HANDLE ; SUCCESS
  ; 
-MAJOR(ZARY,ZTAG,ZNUM) ; RECURSIVE ROUTINE FOR INTERMEDIATE NODES
+MAJOR(ZARY) ; RECURSIVE ROUTINE FOR INTERMEDIATE NODES
  N ZI S ZI=""
+ N ZTAG
  F  S ZI=$O(@ZARY@(ZI)) Q:ZI=""  D  ; FOR EACH SECTION
+ . N ZELEADD S ZELEADD=0
+ . I ZI["@" D  ; END NODE HAS NO VALUE, ONLY ATTRIBUTES
+ . . S ZTAG=$P(ZI,"@",1) ; PULL OUT THE TAG
+ . . K ZATT ; CLEAR OUT LAST ONE
+ . . M ZATT=@ZARY@(ZI,1) ; GET ATTRIBUTE ARRAY
+ . . D STARTELE^MXMLDOM(ZTAG,.ZATT) ; ADD THE NODE
+ . . S ZELEADD=1 ; FLAG TO NOT ADD THE ELEMENT TWICE
+ . I $O(@ZARY@(ZI,""))="" D  ;END NODE
+ . . S ZTAG=ZI ; USE ZI FOR THE TAG
+ . . I 'ZELEADD D STARTELE^MXMLDOM(ZTAG) ; ADD ELEMENT IF NOT THERE
+ . . S ZELEADD=1 ; ADDED AN ELEMENT
+ . . D CHAR^MXMLDOM($G(@ZARY@(ZI))) ; INSERT THE VALUE
+ . I ZELEADD D  Q  ; NO MORE TO DO ON THIS LEVEL
+ . . D ENDELE^MXMLDOM(ZTAG) ; CLOSE THE ELEMENT BEFORE LEAVING
+ . N NEWARY ; INDENTED ARRAY
  . N ZN S ZN=0
  . F  S ZN=$O(@ZARY@(ZI,ZN)) Q:ZN=""  D  ; FOR EACH MULTIPLE
- . . N ZS S ZS=""
- . . I $O(@ZARY@(ZI,ZN,ZS))'["." D  ; END NODES HERE
- . . . N NEWARY
- . . . S NEWARY=$NA(@ZARY@(ZI,ZN))
- . . . D MINOR("NEWARY") ; INSERT THE END NODES
- . . E  F  S ZS=$O(@ZARY@(ZI,ZN,ZS)) Q:ZS=""  D  ; FOR EACH STRING
- . . . I ZS["." D  ; INTERMEDIATE NODE FOUND
- . . . . W !,"IM:",ZS
- . . . W !,ZI,":",ZN,":",ZS_" : ",@ZARY@(ZI,ZN,ZS)
- Q
- ;
-MINOR(ZINARY) ; DOES THE WORK FOR END NODES, HANDLES ATTRIBUTES
- ; 
- N ZZI S ZZI=""
- F  S ZZI=$O(@ZINARY@(ZZI)) Q:ZZI=""  D  ;
- . W !,"MINOR",ZZI,":",@ZINARY@(ZZI)
+ . . D STARTELE^MXMLDOM(ZI) ; ADD THE INTERMEDIATE TAG
+ . . S NEWARY=$NA(@ZARY@(ZI,ZN)) ; INDENT THE ARRAY
+ . . D MAJOR(NEWARY) ; RECURSE FOR INDENTED ARRAY
+ . . D ENDELE^MXMLDOM(ZI) ; END THE INTERMEDIATE TAG
  Q
  ;
@@ -268,4 +284,5 @@
  . . . N ZZV ; PLACE TO STASH THE VALUE
  . . . S ZZV=@ZZIN@(ZZI,ZZN,ZZS) ; VALUE
+ . . . W !,"VALUE:",ZZV
  . . . N GK ; COUNTER
  . . . F GK=1:1:$L(ZZS,".") D  ; FOR EACH INTERMEDIATE NODE
@@ -292,17 +309,4 @@
  Q
  ;
-POP(OSTR,ISTR) ; EXTRINSIC WHICH RETURNS TRUE IF ISTR IS EMPTY
- ; IF ISTR IS NOT EMPTY, LOOKS FOR "." AND "@" AND RETURNS
- ; xxx,1,yyyetc for xxx.yyyetc   and xx@,1,yyy for xxx@yyyetc
- ; OSTR IS PASSED BY REFERENCE AND CONTAINS yyyetc
- I $L(ISTR)=0 Q 1 ; WE ARE DONE
- N ZG,ZN,ZR
- S ZN=1
- I ISTR["." D  ;
- . S ZG=$P(ISTR,".",1)
- . S OSTR=$P(ISTR,".",2)
- . S ZR=ZG_","_ZN_","_OSTR
- Q ZR
- ;
 NEWDOM() ; extrinsic which creates a new DOM and returns the HANDLE
  N CBK,SUCCESS,LEVEL,NODE,HANDLE
@@ -314,4 +318,2 @@
  Q HANDLE
  ;
- 
-
