|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
Attaching an element to existing xml in Java Compute node |
« View previous topic :: View next topic » |
Author |
Message
|
deepeshk79 |
Posted: Thu Jan 07, 2010 9:30 am Post subject: Attaching an element to existing xml in Java Compute node |
|
|
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 |
|
 |
jlaisbett |
Posted: Thu Jan 07, 2010 11:11 am Post subject: |
|
|
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 |
|
 |
deepeshk79 |
Posted: Fri Jan 08, 2010 6:02 pm Post subject: |
|
|
Apprentice
Joined: 25 Mar 2007 Posts: 45 Location: Los Angeles
|
Thanks for the help. The code worked.....  |
|
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
|
|
|
|