ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » How to Create New XML Element Using JCompute Node?

Post new topic  Reply to topic
 How to Create New XML Element Using JCompute Node? « View previous topic :: View next topic » 
Author Message
anandsitha
PostPosted: Fri Jul 29, 2011 3:06 am    Post subject: How to Create New XML Element Using JCompute Node? Reply with quote

Acolyte

Joined: 26 Jul 2011
Posts: 59

Hi -
My msgflow would be FileInput Node--->Java Compute Node--->File Output Node.

I am sending an XML file with English and Maths Element. Now I want to compute total and get it in Output File with new Total Element. Could anyone help me in this suituation. I have tried with

MbElement Total = Student.createElementAsFirstChild(MbElement.TYPE_NAME_VALUE, "Total", "88") but it is not working.

What is comming in the input file is going to the output.


Compute Node Code:

import com.ibm.broker.javacompute.MbJavaComputeNode;
import com.ibm.broker.plugin.*;

public class SimpleComputeMsgFlow_JavaCompute extends MbJavaComputeNode {

public void evaluate(MbMessageAssembly assembly) throws MbException {
MbOutputTerminal out = getOutputTerminal("out");
MbOutputTerminal alt = getOutputTerminal("alternate");


MbMessage inMessage = assembly.getMessage();
MbMessage outMessage = new MbMessage(inMessage);
MbMessageAssembly outAssembly = new MbMessageAssembly(assembly,
outMessage);

try
{


MbElement root = outMessage.getRootElement();

//MbElement Student = root.getLastChild().getFirstChild();
//MbElement Rollno = Student.getFirstChild();
//MbElement English = Student.getNextSibling();
//MbElement Maths = Student.getLastChild();
//MbElement Total = Student.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, "Total", "55");
//MbElement Total = Student.createElementAsLastChild(MbXML.ASIS_ELEMENT_CONTENT,"Total","94");



// add title attribute
//MbElement Total = Student.createElementAsFirstChild(MbElement.TYPE_NAME_VALUE, "Total", "88");
out.propagate(outAssembly);
}
finally
{
outMessage.clearMessage();

}
}

Regards
Sithanandam.V
Back to top
View user's profile Send private message
rekarm01
PostPosted: Fri Jul 29, 2011 4:48 am    Post subject: Re: How to Create New XML Element Using JCompute Node? Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 1415

The XML parser is deprecated. XMLNSC is a better choice.

anandsitha wrote:
I have tried with

MbElement Total = Student.createElementAsFirstChild(MbElement.TYPE_NAME_VALUE, "Total", "88") but it is not working.

The XML parser requires two elements, TYPE_NAME (XML.Element), and TYPE_VALUE (XML.Content).

The XMLNSC parser requires one element, TYPE_NAME_VALUE (XMLNSC.Field).

Consider using the parser-specific field type constants, rather than the generic constants.
Back to top
View user's profile Send private message
lancelotlinc
PostPosted: Fri Jul 29, 2011 4:55 am    Post subject: Reply with quote

Jedi Knight

Joined: 22 Mar 2010
Posts: 4941
Location: Bloomington, IL USA

anandsitha :: [ c o d e ] tags ...!!
_________________
http://leanpub.com/IIB_Tips_and_Tricks
Save $20: Coupon Code: MQSERIES_READER
Back to top
View user's profile Send private message Send e-mail
MQWMBDeveloper
PostPosted: Fri Jul 29, 2011 10:45 am    Post subject: Creating xml element using Javacompute node. Reply with quote

Novice

Joined: 28 Jul 2011
Posts: 16

I just did the same for my project, here's the code.

//create the parse element first
MbElement outParser = outMessage.getRootElement().createElementAsLastChild(MbXMLNSC.PARSER_NAME);
//create the xml element.
MbElement Total= outParser .createElementAsFirstChild(MbXMLNSC.FIELD,"Total",8;
Back to top
View user's profile Send private message
MQWMBDeveloper
PostPosted: Fri Jul 29, 2011 10:47 am    Post subject: Creating xml element using Javacompute node. Reply with quote

Novice

Joined: 28 Jul 2011
Posts: 16

I meant to say "88"); at the end and close brackets
Back to top
View user's profile Send private message
lancelotlinc
PostPosted: Fri Jul 29, 2011 10:54 am    Post subject: Re: Creating xml element using Javacompute node. Reply with quote

Jedi Knight

Joined: 22 Mar 2010
Posts: 4941
Location: Bloomington, IL USA

MQWMBDeveloper wrote:
I meant to say "88"); at the end and close brackets




If you had used [ c o d e ] tag. you would have gotten it right. Did you actually read the post?
_________________
http://leanpub.com/IIB_Tips_and_Tricks
Save $20: Coupon Code: MQSERIES_READER
Back to top
View user's profile Send private message Send e-mail
anandsitha
PostPosted: Mon Aug 01, 2011 12:57 am    Post subject: Reply with quote

Acolyte

Joined: 26 Jul 2011
Posts: 59

Hi-

//create the parse element first
MbElement outParser = outMessage.getRootElement().createElementAsLastChild(MbXMLNSC.PARSER_NAME);
//create the xml element.
MbElement Total= outParser .createElementAsFirstChild(MbXMLNSC.FIELD,"Total",8;


This code only create the output file with <Total>88</Total>. my input file format is below
<?xml version="1.0" encoding="UTF-8"?>
<Student>
<Rollno>22222</Rollno>
<Name>Sithanandam</Name>
<English>95</English>
<Maths>40</Maths>
</Student>

Total Should be calculated ie. Total = English + Maths




Till now in my code
public void evaluate(MbMessageAssembly assembly) throws MbException {
MbOutputTerminal out = getOutputTerminal("out");
MbOutputTerminal alt = getOutputTerminal("alternate");


MbMessage inMessage = assembly.getMessage();
MbMessage outMessage = new MbMessage(inMessage);
MbMessageAssembly outAssembly = new MbMessageAssembly(assembly,
outMessage);

try
{
MbElement root = assembly.getMessage().getRootElement();
MbElement Student = root.getLastChild().getFirstChild();
MbElement RollNo = Student.getFirstChild();
MbElement English = Student.getNextSibling();
MbElement Maths = Student.getLastChild();


out.propagate(outAssembly);
}
finally
{
outMessage.clearMessage();

}
}

How can we modify the above code to calculate Total. And Generate the below output file.

<?xml version="1.0" encoding="UTF-8"?>
<Student>
<Rollno>22222</Rollno>
<Name>Sithanandam</Name>
<English>95</English>
<Maths>40</Maths>
<Total>135</Total>
</Student>

Regards
Sithanandam.V
Back to top
View user's profile Send private message
rekarm01
PostPosted: Mon Aug 01, 2011 1:54 am    Post subject: Re: Creating xml element using Javacompute node. Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 1415

Please put [code] tags around any posted code, to make it more readable.

Use the [Edit] button in the upper right corner of existing posts to fix them, and use the [Preview] button before submitting new posts, to make sure that they are readable.

If outMessage already has an XMLNSC element as last child, it doesn't need another one.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » How to Create New XML Element Using JCompute Node?
Jump to:  



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
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.