|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
Converting one xml to another xml |
« View previous topic :: View next topic » |
Author |
Message
|
trinath |
Posted: Mon Sep 22, 2014 9:39 pm Post subject: Converting one xml to another xml |
|
|
 Apprentice
Joined: 02 Jun 2014 Posts: 34
|
Am using java Compute node
Requirement like this:
giving input
Quote: |
<Employees>
<Employee>
<Name> john </Name>
<Number>1</Number>
<Salary>50000</Salary>
</Employee>
<Employee>
<Name>Ram</Name>
<Number>2</Number>
<Salary>60000</Salary>
</Employee>
</Employees> |
expected output
Quote: |
<Employees>
<Employee>
john with id 1 and Getting salary 50000
</Employee>
<Employee>
Ram with id 2 and Getting salary 60000
</Employee>
</Employees> |
and am using code
Quote: |
public class Xml_Xml_MsgFlow_JavaCompute extends MbJavaComputeNode
{
public void evaluate(MbMessageAssembly contact admin)
throws MbException
{
MbMessage inMessage = contact admin.getMessage();
MbMessage outMessage = new MbMessage(); // create an empty output message
MbMessageAssembly outAssembly = new MbMessageAssembly(contact admin, outMessage);
copyMessageHeaders(inMessage, outMessage); // copy headers from the input message
// Add user code below
MbElement inRoot = inMessage.getRootElement();
MbElement outRoot = outMessage.getRootElement();
MbElement outBody = outRoot.createElementAsLastChild("XMLNSC"); // create the 'Body' XMLNSC element
// declare the class to create statements for each employeelist
final ForEachChildOperation createStatement = new ForEachChildOperation("Employee") {
protected void forEachElement(MbElement Employee) throws MbException
{
MbElement employeeList = getOutputElement();
MbElement cursor = Employee.getFirstChild();
String name = (String)cursor.getValue();
cursor = cursor.getNextSibling();
String id = (String)cursor.getValue();
cursor = cursor.getNextSibling();
String salary = (String)cursor.getValue();
String details = name+ "with id"+ id+ " and Getting salary "+salary;
MbElement statement = employeeList.createElementAsLastChild(MbXMLNSC.FOLDER, "Statement", null);
MbElement employee = statement.createElementAsLastChild(MbXMLNSC.FOLDER, "Employee", null);
employee.createElementAsLastChild(MbXMLNSC.FIELD, "Name", name);
employee.createElementAsLastChild(MbXMLNSC.FIELD, "Number", id);
employee.createElementAsLastChild(MbXMLNSC.FIELD, "Salary", salary);
employee.createElementAsLastChild(MbXMLNSC.FIELD, "Employee", details);
}
};
getOutputTerminal("out").propagate(outAssembly);
}
public void copyMessageHeaders(MbMessage inMessage, MbMessage outMessage) throws MbException
{
MbElement outRoot = outMessage.getRootElement();
MbElement header = inMessage.getRootElement().getFirstChild();
while(header != null && header.getNextSibling() != null)
{
outRoot.addAsLastChild(header.copy());
header = header.getNextSibling();
}
}
abstract class ForEachChildOperation
{
private String emp = null;
private MbElement outputElement = null;
public ForEachChildOperation(String emp) throws MbException
{
this.emp = emp;
}
public MbElement getOutputElement()
{
return outputElement;
}
protected void before() throws MbException { }
protected abstract void forEachElement(MbElement element) throws MbException;
protected void after() throws MbException { }
public void evaluate(MbElement element) throws MbException
{
before();
MbElement child = element.getFirstChild();
while(child != null)
{
String childName = (String)child.getName();
if(childName.equals(emp))
forEachElement(child);
child = child.getNextSibling();
}
after();
}
}
}
|
am not getting solution, what wrong with my code |
|
Back to top |
|
 |
smdavies99 |
Posted: Mon Sep 22, 2014 9:55 pm Post subject: |
|
|
 Jedi Council
Joined: 10 Feb 2003 Posts: 6076 Location: Somewhere over the Rainbow this side of Never-never land.
|
I see that this is a repost of this
http://www.mqseries.net/phpBB2/viewtopic.php?t=68502
You would have been better continuing that thread.
 _________________ 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 |
|
 |
|
|
 |
|
Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|