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 » Attaching an element to existing xml in Java Compute node

Post new topic  Reply to topic
 Attaching an element to existing xml in Java Compute node « View previous topic :: View next topic » 
Author Message
deepeshk79
PostPosted: Thu Jan 07, 2010 9:30 am    Post subject: Attaching an element to existing xml in Java Compute node Reply with quote

Apprentice

Joined: 25 Mar 2007
Posts: 45
Location: Los Angeles

I am facing an issue in adding a string as an MbElement. That string will be having tags.
String docString = "<check>asdfsdafdfdf</check>";
Input XML is as below:
Code:

  <?xml version="1.0" encoding="UTF-8"?>         
<?ABHeader version="1.0"?>           
<ABEnvelope>           
 <Test>testing</Test>               
 </ABEnvelope>         

And my code is like below:
Code:

public MbMessageAssembly generateOrch(MbMessageAssembly assembly)        throws MbException
  {
   MbElement outBody = assembly.getMessage().getRootElement().getLastChild();
 
   String docString = "<check>asdfsdafdfdf</check>";
   
   outBody.getFirstElementByPath("./ABEnvelope")
   .createElementAsLastChildFromBitstream(docString.getBytes(),"", "", "", "", 0, 0, 0);
return assembly;
}

Output XML is as below:
Code:

  <?xml version="1.0" encoding="UTF-8"?>         
<?ABHeader version="1.0"?>           
<ABEnvelope>           
 <Test>testing</Test>  <XML><check>asdfsdafdfdf</check></XML>           
 </ABEnvelope>     

Here an extra <XML> is coming which is wrong. I want the output without <XML> element.
Back to top
View user's profile Send private message AIM Address
jlaisbett
PostPosted: Thu Jan 07, 2010 11:11 am    Post subject: Reply with quote

Apprentice

Joined: 27 Nov 2009
Posts: 39

createElementAsLastChildFromBitstream is designed for creating a message body, as in the whole message body so it creates a parent tree that is the parser being used.

That said you can do what you want but it takes a bit more effort, the below would do it:

Code:
public MbMessageAssembly generateOrch(MbMessageAssembly assembly) throws MbException
{
   MbElement outBody = assembly.getMessage().getRootElement().getLastChild();

   String docString = "<check>asdfsdafdfdf</check>";

   // createdElement will reference the parser element
   MbElement createdElement = outBody.getFirstElementByPath("./ABEnvelope")
   .createElementAsLastChildFromBitstream(docString.getBytes(),"", "", "", "", 0, 0, 0);
   // createdElementChild will reference the check element
   MbElement createdElementChild = createdElement.getFirstChild();
   // Detach them from the message
   createdElement.detach();
   createdElementChild.detach();
   // Add the child back to the message without the parser element
   outBody.getFirstElementByPath("./ABEnvelope").addAsLastChild(createdElementChild);
   
   return assembly;
}
Back to top
View user's profile Send private message
deepeshk79
PostPosted: Fri Jan 08, 2010 6:02 pm    Post subject: Reply with quote

Apprentice

Joined: 25 Mar 2007
Posts: 45
Location: Los Angeles

Thanks for the help. The code worked.....
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Attaching an element to existing xml in Java Compute 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.