Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old August 21st, 2009, 01:33 AM
Registered User
 
Join Date: Aug 2009
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
Question Convert ASCII (Byte[] Array) to Binary

How can I convert XML data in ASCII format, to a single element containing Base-64 data.

In other words, how can I convert a list of ASCII elements like the following:

<Document>
<data>208</data>
<data>207</data>
<data>17</data>
<data>224</data>
<data>161</data>
<data>177</data>
<data>26</data>
<data>225</data>
<data>0</data>
.
.
etc....
<Document>


To its base64 representation, something like this:

<Document>
/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHB wgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL
</Document>



(the ASCII XML elements represent a small section of a word document)

Thanks
Reply With Quote
  #2 (permalink)  
Old August 21st, 2009, 04:50 AM
mhkay's Avatar
Wrox Author
Points: 18,438, Level: 59
Points: 18,438, Level: 59 Points: 18,438, Level: 59 Points: 18,438, Level: 59
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,954
Thanks: 0
Thanked 290 Times in 285 Posts
Default

First point: ASCII stops at 127. When you say ASCII, I assume you mean Unicode or perhaps iso-8859-1?

Base64 is an encoding of a byte stream. So I assume you want these codes treated as single bytes. In that case, it's actually immaterial whether they are ASCII codes or iso-8859-1 codes or anything else - they are just bytes.

There's no direct way of doing this in pure XSLT 1.0 or 2.0. Saxon however has an extension function that you could use:

http://www.saxonica.com/documentatio...e64binary.html

Calling

Code:
<xsl:value-of select="saxon:octets-to-base64Binary(/Document/data/xs:integer(.))"/>
should do the trick.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert bytes to byte[] array d-mart Java Basics 4 April 24th, 2009 11:09 AM
Converting an ASCII character to binary? skyraider Visual Basic 2005 Basics 0 May 7th, 2006 09:20 PM
Binary Data OR Byte() OR BitArray... to Integer pgjuun2 VB How-To 0 March 13th, 2005 11:52 PM
Differences between ASCII and Binary Files kuba C# 1 October 17th, 2004 08:22 PM
URGENT byte associated with the ASCII code shine Javascript How-To 0 July 5th, 2004 10:41 AM



All times are GMT -4. The time now is 08:16 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.