cancel
Showing results for 
Search instead for 
Did you mean: 

Hexadecimal conversion

Former Member
0 Kudos

Hi,

I have an XML file & i have converted it into hexadecimal to store in backend.Now i have to convert this hexadecimal value to XML file.How can i do that .Apart from that this xml should be in correct format.

thanx & regards

Sumit

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

hi

good

go through this link

http://www.stylusstudio.com/docs/v2006/d_edit9.html

thanks

mrutyun^

Former Member
0 Kudos

Hi,

I'm not sure if this the correct way to store files in DB. Why don't you just take the bytes with the correct encoding, save them in the DB. When you want to extract the String from the DB, you could read the bytes in byte array, write them in file or create a string with the proper encoding.

You could encode String as a BigInteger but this is highly ineffective.

Cheers,

Toshe

Former Member
0 Kudos

Hi Toshe,

Actually this is an XML document what i m storing in DB.DB is sap r/3 & its data type is xstring which takes only hex values.I m able to convert it back to string & its printing complete xml as a string but the problem is that i want xml document bcos i have to render it on webdynpro UI.Can you tell me how can i convert this string to an XML document??

regards

Sumit

Former Member
0 Kudos

Hi Sunil,

I got your problem, you need to convert the <b>String</b> to a <b>Document</b> object. Use the following code to do it,

String str  = "<xml></xml>"; 
InputStream is = new StringBufferInputStream(str);
DocumentBuilderFactory dBF = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = dBF.newDocumentBuilder();
Document doc = builder.parse(is); 

I'm sure that'll help you.

Best regards,

Guru.

Former Member
0 Kudos

Hi Guru,

Thanks for help.It is working now.

regards

Sumit

Former Member
0 Kudos

Hi Sumit,

If my reply/code helped you then please reward me points for the same.

Regards,

Guru.

Former Member
0 Kudos

Hi Sumit,

Can you elaborate on the method (post some code snippet as well) that you used in the conversion. That will help me in solving your problem.

Regards,

Guru.

Former Member
0 Kudos

Hi Guru,

This is the code :

String d = writtenDocument.toString();

byte[] bytes = d.getBytes("US-ASCII");

BigInteger bi = new BigInteger(bytes);

String s = bi.toString(16);

if (s.length() % 2 != 0) {

// Pad with 0

s = "0" + s;

}

Here writtenDocument is org.w3c.dom.Document.

Thanx & Regards

Sumit