| Author | 
		  Message
		 | 
		
		  | trinath | 
		  
		    
			  
				 Posted: Sun Sep 21, 2014 11:33 pm    Post subject: Java Compute Node | 
				     | 
			   
			 
		   | 
		
		
		    Apprentice
 
 Joined: 02 Jun 2014 Posts: 34
  
  | 
		  
		    
			  
				Hello Please Provide code for changing one xml to different xml  by using Java compute node 
 
 
 
My Requirement like:
 
 
am giving input like this 
 
<Employees>
 
 
	<Employee>
 
		<Name> john </Name>
 
		<Number> 1 </Number>
 
               <Salary> 5000 </Salary>
 
	</Employee>
 
 
	<Employee>
 
		<Name>Ram</Name>
 
		<Number> 2</Number>
 
                <Salary> 6000 </Salary>
 
	</Employee>
 
 
</Employees>
 
-----------------------------
 
 
am accepting output like this 
 
<Employees>
 
	<Employee>
 
		john with id 1 getting salary 5000
 
	</Employee>
 
 
	<Employee>
 
		Ram with id 2 getting salary 6000
 
	</Employee>
 
 
</Employees>
 
-------------------- | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | smdavies99 | 
		  
		    
			  
				 Posted: Mon Sep 22, 2014 12:20 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		    Jedi Council
 
 Joined: 10 Feb 2003 Posts: 6076 Location: Somewhere over the Rainbow this side of Never-never land. 
  | 
		  
		    
			  
				What have you tried? 
 
What went wrong?
 
 
This is very easy using ESQL _________________ WMQ User since 1999
 
MQSI/WBI/WMB/'Thingy' User since 2002
 
Linux user since 1995
 
 
 
Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions. | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | trinath | 
		  
		    
			  
				 Posted: Mon Sep 22, 2014 12:53 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		    Apprentice
 
 Joined: 02 Jun 2014 Posts: 34
  
  | 
		  
		    
			  
				| It is  easy in esql, but i need  in java with the help of java compute node. | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | vicentius | 
		  
		    
			  
				 Posted: Mon Sep 22, 2014 1:50 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		    Apprentice
 
 Joined: 01 Mar 2013 Posts: 28
  
  | 
		  
		    
			  
				Please share with us your context, so we can help. As smdavies already mentioned, let us know what have you tried so far, let us know where you got stuck. 
 
You will find it easy to get help to the issues you encounter, but not many people will jump in to write *your* code. Understand that people around online communities like to help out, but they generally have limited time to invest in such activities for free. | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | trinath | 
		  
		    
			  
				 Posted: Mon Sep 22, 2014 2:21 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		    Apprentice
 
 Joined: 02 Jun 2014 Posts: 34
  
  | 
		  
		    
			  
				===> Input flile 
 
 
 
<Employees>
 
	<Employee>
 
		<Name>John</Name>
 
		<Number>1</Number>
 
	</Employee>
 
	<Employee>
 
		<Name>shreeya</Name>
 
		<Number>2</Number>
 
	</Employee>
 
 
</Employees>
 
 
 
===> Expected Out Put
 
 
 
<Employees>
 
	<Employee> John with id 1 </Employee>
 
	<Employee> shreeya with id 2 </Employee>
 
</Employees>
 
 
 
am trying this code
 
----------------------
 
 
 
// Add user code below
 
			
 
			MbElement inRoot = inMessage.getRootElement().getLastChild();
 
 
			MbElement firstEle = inRoot.getFirstElementByPath("Employees/Employee").getFirstChild();
 
			String firstEle1 = (String)firstEle.getValue();
 
			
 
			MbElement lastEle = inRoot.getFirstElementByPath("Employees/Employee").getLastChild();
 
			String lastEle1 = (String)lastEle1.getValue();
 
			
 
			
 
			MbElement firstEle2 = inRoot.getFirstElementByPath("Employees/Employee").getNextSibling().getFirstChild();
 
			String firstEle22 = (String)firstEle2.getValue();
 
			
 
			MbElement lastEle2 = inRoot.getFirstElementByPath("Employees/Employee").getNextSibling().getLastChild();
 
			String lastEle22 = (String)lastEle2.getValue();
 
			
 
			
 
 
			String total = "<Employee>" + firstEle1+" " + "with id" + "  " + lastEle1 + "</Employee>" ;
 
			String total1 = "<Employee>" +firstEle22+" " + "with id" + "  " + lastEle22 + "</Employee>" ;
 
			
 
			String aa= "<Employees>"+total+total1 +"</Employees>";
 
			 
 
			MbElement outRoot = outMessage.getRootElement();
 
			MbElement outParser = outRoot.createElementAsLastChild(MbBLOB.PARSER_NAME);
 
		           
 
		   	MbElement outBodyEl2 = outParser.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, "BLOB", aa.getBytes());
 
		            
 
			
 
// End of user code
 
 
it is working but,how to use looping conditions in this code for accessing multiple childs in  every sibling | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | mqjeff | 
		  
		    
			  
				 Posted: Mon Sep 22, 2014 5:09 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		   Grand Master
 
 Joined: 25 Jun 2008 Posts: 17447
  
  | 
		  
		    
			  
				Ok, so why are you building a message string, instead of copying elements from one MbRoot to another?
 
 
Why are you building a string, rather than creating new MbElements?
 
 
Have you reviewed the Mb Java API docs?  The samples? | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | smdavies99 | 
		  
		    
			  
				 Posted: Mon Sep 22, 2014 6:52 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		    Jedi Council
 
 Joined: 10 Feb 2003 Posts: 6076 Location: Somewhere over the Rainbow this side of Never-never land. 
  | 
		  
		    
			  
				
   
	| mqjeff wrote: | 
   
  
	
 
 
Why are you building a string, rather than creating new MbElements?
 
 
 | 
   
 
 
 
Perhaps the poster wants to make life difficult for themselves. Having to use Java is probably not enough torture.
 
 
{ducks to avoid incoming brickbats} _________________ WMQ User since 1999
 
MQSI/WBI/WMB/'Thingy' User since 2002
 
Linux user since 1995
 
 
 
Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions. | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | vicentius | 
		  
		    
			  
				 Posted: Mon Sep 22, 2014 7:28 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		    Apprentice
 
 Joined: 01 Mar 2013 Posts: 28
  
  | 
		  
		    
			  
				
   
	| mqjeff wrote: | 
   
  
	| [...]Why are you building a string, rather than creating new MbElements?[...] | 
   
 
 
 
Probably working with the same mindset as creating fields in ESQL using SET instead of CREATE. | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | 
		    
		   |