| Author | 
		  Message
		 | 
		
		  | Galichet | 
		  
		    
			  
				 Posted: Wed Jan 22, 2003 4:10 am    Post subject: Perform a TRIM in an entire XML tree | 
				     | 
			   
			 
		   | 
		
		
		   Acolyte
 
 Joined: 26 Jun 2001 Posts: 69 Location: Paris - France 
  | 
		  
		    
			  
				Hi all,
 
 
I would liketo perform a TRIM on each tag value and each attribute in an XML tree.
 
For Example, the following XML message :
 
<MESSAGE>
 
   <FIELD1 ATT1="   AA" ATT2="123  ">
 
      <F1>SMITH   </F1>
 
      <F2>GEORGE    </F2>
 
   </FIELD1>
 
</MESSAGE>
 
 
Should be translated to :
 
<MESSAGE>
 
   <FIELD1 ATT1="AA" ATT2="123">
 
      <F1>SMITH</F1>
 
      <F2>GEORGE</F2>
 
   </FIELD1>
 
</MESSAGE>
 
 
I would like to have a generic process, I can have a lot of different structures.
 
 
Anyone have an idea ?
 
 
Thanks a lot
 
 
 
Eric | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | lillo | 
		  
		    
			  
				 Posted: Wed Jan 22, 2003 6:27 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		   Master
 
 Joined: 11 Sep 2001 Posts: 224
  
  | 
		  
		    
			  
				Use the following ESQL code:
 
   
	| Code: | 
   
  
	SET OutputRoot = InputRoot;
 
-- Enter SQL below this line.  SQL above this line might be regenerated, causing any modifications to be lost.
 
DECLARE refRoot REFERENCE TO OutputRoot.XML.*[1]; 
 
DECLARE xref REFERENCE TO OutputRoot.XML.*[1]; 
 
DECLARE refAttr REFERENCE TO OutputRoot.XML.*[1];
 
DECLARE done INTEGER; 
 
DECLARE i INTEGER;
 
SET done=0; 
 
 
WHILE (LASTMOVE(xref) AND done=0) DO 
 
   -- Trim the element
 
   SET xref = TRIM(xref);
 
   -- Trim the attribute
 
   MOVE refAttr TO xref;
 
   MOVE refAttr FIRSTCHILD TYPE 0x03000000;
 
   WHILE LASTMOVE(refAttr) DO
 
      SET refAttr = TRIM(refAttr);
 
      MOVE refAttr NEXTSIBLING REPEAT TYPE;
 
   END WHILE;
 
 
   MOVE xref FIRSTCHILD; 
 
   IF NOT LASTMOVE(xref) THEN 
 
      MOVE xref NEXTSIBLING; 
 
      WHILE ( NOT LASTMOVE(xref) and (done=0)) do 
 
         MOVE xref PARENT; 
 
            If samefield (xref,refRoot) THEN 
 
               SET done = 1; 
 
            end if; 
 
            MOVE xref NEXTSIBLING; 
 
         END WHILE;  
 
   END IF; 
 
END WHILE;  | 
   
 
 _________________ Lillo
 
IBM Certified Specialist - WebSphere MQ | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | Galichet | 
		  
		    
			  
				 Posted: Wed Jan 22, 2003 7:05 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		   Acolyte
 
 Joined: 26 Jun 2001 Posts: 69 Location: Paris - France 
  | 
		  
		    
			  
				Thanks for your quick response Lillo    
 
 
I've copied the ESQL in my compute node box but I've a syntax problem :
 
 
The Control center is not happy with the 2 following lines :
 
MOVE refAttr FIRSTCHILD TYPE 0x03000000;
 
MOVE refAttr NEXTSIBLING REPEAT TYPE;
 
 
I've checked the documentation but without finding anything (at least about REPEAT keyword...
 
 
 
Eric | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | lillo | 
		  
		    
			  
				 Posted: Wed Jan 22, 2003 7:28 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		   Master
 
 Joined: 11 Sep 2001 Posts: 224
  
  | 
		  
		    
			  
				The code is for WMQI2.1 CSD2 or above.
 
 
Cheers, _________________ Lillo
 
IBM Certified Specialist - WebSphere MQ | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | Galichet | 
		  
		    
			  
				 Posted: Wed Jan 22, 2003 7:58 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		   Acolyte
 
 Joined: 26 Jun 2001 Posts: 69 Location: Paris - France 
  | 
		  
		    
			  
				Ok thank you very much
 
 
I'm going to upgrade my wmqi.
 
 
 
Eric | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | Galichet | 
		  
		    
			  
				 Posted: Thu Jan 23, 2003 11:58 pm    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		   Acolyte
 
 Joined: 26 Jun 2001 Posts: 69 Location: Paris - France 
  | 
		  
		    
			  
				Hi,
 
 
I've successfully tested this in my flow, that's great    
 
 
But I've seen that if the input XML message contains a header like :
 
<?xml version="1.0" encoding="UTF-8"?>
 
The flow doesn't work    
 
 
I've tried to remove this header just before, but without success ... Is it possible to do it for all input XML message ? (is there is a header, then remove it, if not continue) 
 
 
Thanks for your help
 
 
Eric | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | lillo | 
		  
		    
			  
				 Posted: Fri Jan 24, 2003 2:53 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		   Master
 
 Joined: 11 Sep 2001 Posts: 224
  
  | 
		  
		    
			  
				Replace the first line with this code. I just change *[1] for *[LAST]
 
   
	| Code: | 
   
  
	
 
DECLARE refRoot REFERENCE TO OutputRoot.XML.*[LAST]; 
 
DECLARE xref REFERENCE TO OutputRoot.XML.*[LAST]; 
 
DECLARE refAttr REFERENCE TO OutputRoot.XML.*[LAST]; 
 
 | 
   
 
 
 
It won´t remove the XML declaration. But it will work.
 
 
Cheers _________________ Lillo
 
IBM Certified Specialist - WebSphere MQ | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | 
		    
		   |