Author |
Message
|
alewis |
Posted: Thu Nov 02, 2006 2:47 pm Post subject: XML to BLOB to java.lang.String conversion |
|
|
Novice
Joined: 20 Aug 2006 Posts: 13
|
While converting XML to byte[] and retrieving the value using new String(byte[]), all start and end tags are replaced by > and < The incoming XML is an valid XML and the code is as shown below:
Code: |
MbElement inRoot=contact admin.getMessage().getRootElement();
MbElement inBody=inRoot.getLastChild();
String parserName=inBody.getParserClassName();
MbElement outRoot=outMessage.getRootElement();
outRoot.evaluateXPath("string(./?Properties/?MessageSet[set-value('FHPO4KS002001')])");
outRoot.evaluateXPath("string(./?Properties/?MessageType[set-value('IJLog')])");
outRoot.evaluateXPath("string(./?Properties/?MessageFormat[set-value('XML1')])");
MbElement outBody=outRoot.createElementAsLastChild("MRM");
MbElement payload=outBody.createElementAsLastChild(MbElement.TYPE_NAME,"Payload",null);
String data = null;
// log the payload if the incoming message is a XML or XMLNS
if(parserName.equalsIgnoreCase(MbXML.PARSER_NAME) || parserName.equalsIgnoreCase(MbXMLNS.PARSER_NAME)){
data = new String(inBody.toBitstream(null,null,null,0,0,0));
}
payload.createElementAsLastChild(MbElement.TYPE_NAME,"Data",data); |
The contents within "Data" contain < and >
Is there a way to retain the XML start and end tags??
|
|
Back to top |
|
 |
kimbert |
Posted: Tue Nov 07, 2006 3:01 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
What are you trying to do? |
|
Back to top |
|
 |
alewis |
Posted: Tue Nov 07, 2006 5:17 am Post subject: |
|
|
Novice
Joined: 20 Aug 2006 Posts: 13
|
I need to store the entire incoming message(InputBody) which can be an MRM, XML, XMLNS or a BLOB. This can be done using the copyElementTree() on the parser element for MRM,XML or XMLNS but if used on a BLOB, the value that will be stored in the element will a byte[]. Inorder to store the value, I first use the toBitStream() if the incoming message is XML,XMLNS or MRM and if the parser is BLOB I do a getValue() which returns a byte[]. The byte array obtained is then passed to a String(byte[]) which can store the value as a String.
The problem with this approach is that any markup is replaced by < and >
Can you please provide me a recommended solution so that start and ending tags are not replaced by < and > |
|
Back to top |
|
 |
jefflowrey |
Posted: Tue Nov 07, 2006 5:23 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Do you see the < when looking at Data inside the Java code, or only when looking at Data outside the Java code? _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
alewis |
Posted: Tue Nov 07, 2006 6:31 am Post subject: |
|
|
Novice
Joined: 20 Aug 2006 Posts: 13
|
Its after the call to new String(byte[]). |
|
Back to top |
|
 |
jefflowrey |
Posted: Tue Nov 07, 2006 6:45 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
....
So that's in the Java debugger that you're seeing this?
Or in the Broker debugger after you leave the JCN? _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
kimbert |
Posted: Tue Nov 07, 2006 7:13 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
So you are parsing the message, and then immediately serializing it in order to store the bitstream. That's going to perform badly.
Why not
- parse in the BLOB domain
- save InputRoot.BLOB.BLOB in the environment
- reparse as XML/XMLNS/MRM
To answer your question, < and > get changed to < and > whenever they appear in the value of an XML element. If you want to store XML text in an XML element you should always put it inside a CDATA section, or else base64 encode it. |
|
Back to top |
|
 |
alewis |
Posted: Tue Nov 07, 2006 7:35 am Post subject: |
|
|
Novice
Joined: 20 Aug 2006 Posts: 13
|
The incoming BLOB can be a TDS or XMLNS message. How do i know whats the format of the message before I try reparsing the message?
Should I try
Code: |
createElementAsLastChildFromBitstream(byte[] bitstream,
XMLNS.PARSER_NAME,
null,
null,
null,
0,
0,
0) |
and if this fails then i know the message is not an XML message and i can do a new String(byte[]) to get a TDS message.
Do i have to define an element of type base64Binary and what do i need to set it here
Also there is one more requirement that i have not mentioned and I am sorry for that. I need to send the entire message XML or TDS to a java object which is used for audit. In this case I will have to get the String representation of the entire message which will give me the < and > |
|
Back to top |
|
 |
bhaski |
Posted: Tue Apr 03, 2007 4:57 am Post subject: late but with solution...... |
|
|
 Voyager
Joined: 13 Sep 2006 Posts: 78 Location: USA
|
Hi
I think It is too late to give the solution, any way if you have a chance just find out the ways to conver the string values to XML ( < and ... )
use XML.AsisElementContent to attach the string part as a XML.
BR
Bhaski. |
|
Back to top |
|
 |
|