| Author | 
		  Message
		 | 
		
		  | sboucher | 
		  
		    
			  
				 Posted: Fri Feb 13, 2004 5:31 am    Post subject: XML Output Question | 
				     | 
			   
			 
		   | 
		
		
		   Acolyte
 
 Joined: 27 Oct 2002 Posts: 52
  
  | 
		  
		    
			  
				The following raw input generates the XML shown Below using MQSI2.1:
 
20040211221051234222222022222233333303333334444441444444:
 
 
- <MSG>
 
- <HDR_DATA>
 
  <DATE>20040211</DATE> 
 
  <STORE_NUM>2210</STORE_NUM> 
 
  <REG_NUM>5</REG_NUM> 
 
  <TRANS_NUM>1234</TRANS_NUM> 
 
  </HDR_DATA>
 
- <DTAIL_DATA>
 
  <CODE>222222</CODE> 
 
  <SIGN_FLG>0</SIGN_FLG> 
 
  <QTY>222222</QTY> 
 
  </DTAIL_DATA>
 
- <DTAIL_DATA>
 
  <CODE>333333</CODE> 
 
  <SIGN_FLG>0</SIGN_FLG> 
 
  <QTY>333333</QTY> 
 
  </DTAIL_DATA>
 
- <DTAIL_DATA>
 
  <CODE>444444</CODE> 
 
  <SIGN_FLG>1</SIGN_FLG> 
 
  <QTY>444444</QTY> 
 
  </DTAIL_DATA>
 
  </MSG>
 
 
My Compute Node looks like this:
 
 
SET OutputRoot.XML."MSG"."HDR_DATA"[] = InputRoot.MRM."HDR_DATA"[];
 
SET OutputRoot.XML."MSG"."DTAIL_DATA"[] = InputRoot.MRM."DTAIL_DATA"[];
 
SET OutputRoot.MQMD.Format = 'XML     ';
 
 
 
My question is this:  Can I somehow manipulate the above XML so the HDR_DATA also repeats with the DTAIL_DATA to look like:
 
 
- <MSG>
 
- <HDR_DATA>
 
  <DATE>20040211</DATE> 
 
  <STORE_NUM>2210</STORE_NUM> 
 
  <REG_NUM>5</REG_NUM> 
 
  <TRANS_NUM>1234</TRANS_NUM> 
 
  </HDR_DATA>
 
- <DTAIL_DATA>
 
  <DATE>20040211</DATE> 
 
  <STORE_NUM>2210</STORE_NUM> 
 
  <REG_NUM>5</REG_NUM> 
 
  <TRANS_NUM>1234</TRANS_NUM> 
 
  <CODE>222222</CODE> 
 
  <SIGN_FLG>0</SIGN_FLG> 
 
  <QTY>222222</QTY> 
 
  </DTAIL_DATA>
 
- <DTAIL_DATA>
 
  <DATE>20040211</DATE> 
 
  <STORE_NUM>2210</STORE_NUM> 
 
  <REG_NUM>5</REG_NUM> 
 
  <TRANS_NUM>1234</TRANS_NUM> 
 
  <CODE>333333</CODE> 
 
  <SIGN_FLG>0</SIGN_FLG> 
 
  <QTY>333333</QTY> 
 
  </DTAIL_DATA>
 
- <DTAIL_DATA>
 
   <DATE>20040211</DATE> 
 
  <STORE_NUM>2210</STORE_NUM> 
 
  <REG_NUM>5</REG_NUM> 
 
  <TRANS_NUM>1234</TRANS_NUM> 
 
  <CODE>444444</CODE> 
 
  <SIGN_FLG>1</SIGN_FLG> 
 
  <QTY>444444</QTY> 
 
  </DTAIL_DATA>
 
  </MSG> _________________ Scott A. Boucher
 
Database Administartor | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | Missam | 
		  
		    
			  
				 Posted: Fri Feb 13, 2004 6:32 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		   Chevalier
 
 Joined: 16 Oct 2003 Posts: 424
  
  | 
		  
		    
			  
				| Yes You Can,But you didn't show how your header should repeat. | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | sboucher | 
		  
		    
			  
				 Posted: Fri Feb 13, 2004 7:31 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		   Acolyte
 
 Joined: 27 Oct 2002 Posts: 52
  
  | 
		  
		    
			  
				I'm a little new to all this so bear with me:
 
 
I would like Date,Store_Num,Reg_Num,Trans_Num (HDR_DATA) to also appear with each repeating set of data which is comprised of Code,Sign,Qty (DTAIL_DATA) to be output as follows for each repeating element
 
 
DATE
 
STORE_NUM
 
REG_NUM
 
TRANS_NUM
 
CODE
 
SIGN
 
QTY
 
.
 
.
 
.
 
DATE
 
STORE_NUM
 
REG_NUM
 
TRANS_NUM
 
CODE
 
SIGN
 
QTY _________________ Scott A. Boucher
 
Database Administartor | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | Missam | 
		  
		    
			  
				 Posted: Fri Feb 13, 2004 10:49 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		   Chevalier
 
 Joined: 16 Oct 2003 Posts: 424
  
  | 
		  
		    
			  
				You can do it in more than one way.here is one
 
 
Declare index Integer;
 
Declare X Integer;
 
Set X =1;
 
Set index = CARDINALITY(InputRoot.MRM."DTAIL_DATA"[])
 
While (X <= index) DO
 
SET OutputRoot.XML."MSG"."HDR_DATA"[X] = InputRoot.MRM."HDR_DATA"[1]; 
 
SET OutputRoot.XML."MSG"."DTAIL_DATA"[X] = InputRoot.MRM."DTAIL_DATA"[X]; 
 
 
Set X=X+1;
 
End While; | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | sboucher | 
		  
		    
			  
				 Posted: Fri Feb 13, 2004 11:53 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		   Acolyte
 
 Joined: 27 Oct 2002 Posts: 52
  
  | 
		  
		    
			  
				Put your code in a new compute node - Got a syntax error then placed a semicolon after the 'set index' and error went away. My main goal is to get the XML data into a format that can be easily read into a database.  Here is the output your code generated:
 
 
- <MSG>
 
- <HDR_DATA>
 
  <DATE>20040213</DATE> 
 
  <STORE_NUM>2210</STORE_NUM> 
 
  <REG_NUM>5</REG_NUM> 
 
  <TRANS_NUM>1234</TRANS_NUM> 
 
  </HDR_DATA>
 
- <HDR_DATA>
 
  <DATE>20040213</DATE> 
 
  <STORE_NUM>2210</STORE_NUM> 
 
  <REG_NUM>5</REG_NUM> 
 
  <TRANS_NUM>1234</TRANS_NUM> 
 
  </HDR_DATA>
 
- <HDR_DATA>
 
  <DATE>20040213</DATE> 
 
  <STORE_NUM>2210</STORE_NUM> 
 
  <REG_NUM>5</REG_NUM> 
 
  <TRANS_NUM>1234</TRANS_NUM> 
 
  </HDR_DATA>
 
- <DTAIL_DATA>
 
  <CODE>222222</CODE> 
 
  <SIGN_FLG>0</SIGN_FLG> 
 
  <QTY>222222</QTY> 
 
  </DTAIL_DATA>
 
- <DTAIL_DATA>
 
  <CODE>111111</CODE> 
 
  <SIGN_FLG>0</SIGN_FLG> 
 
  <QTY>111111</QTY> 
 
  </DTAIL_DATA>
 
- <DTAIL_DATA>
 
  <CODE>333333</CODE> 
 
  <SIGN_FLG>1</SIGN_FLG> 
 
  <QTY>333333</QTY> 
 
  </DTAIL_DATA>
 
  </MSG>
 
 
Can we somehow get what normally is in the HDR_DATA combined with each DTAIL_DATA record.  At least we now have a HDR for Each DTAIL  but if I loaded many transactions like these  into a database I wouldn't be guaranteed the HDR and DTAIL would stay together as a transaction when populating the database.  Thanks for your patience _________________ Scott A. Boucher
 
Database Administartor | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | Missam | 
		  
		    
			  
				 Posted: Sat Feb 14, 2004 6:52 pm    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		   Chevalier
 
 Joined: 16 Oct 2003 Posts: 424
  
  | 
		  
		    
			  
				
   
	| Code: | 
   
  
	
 
Declare index Integer; 
 
Declare X Integer; 
 
DECLARE outptr REFERENCE TO OutputRoot.XML."MSG"[1];
 
Set X =1; 
 
Set index = CARDINALITY(InputRoot.MRM."DTAIL_DATA"[]) ;
 
While (X <= index) DO 
 
CREATE LASTCHILD OF outptr DOMAIN 'XML' NAME 'HDR_DATA';
 
SET outptr."HDR_DATA"[LAST] = InputRoot.MRM."HDR_DATA"[1]; 
 
CREATE LASTCHILD OF outptr DOMAIN 'XML' NAME 'DTAIL_DATA';
 
SET outptr."DTAIL_DATA"[LAST] = InputRoot.MRM."DTAIL_DATA"[X]; 
 
 
Set X=X+1; 
 
End While;
 
 | 
   
 
 
Try this and see | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | 
		    
		   |