VBA – Reading a Base64 Element into XML and using as Byte Array

Ok, more VBA

Getting a response back as Base64, but when trying to convert it from XML to binary data just having issues.. coming back as ASCII which converts wacked.

What you need to do:

Dim MyInfo As MSXML2.IXMLDOMNodeList
Set MyInfo = xmlDoc.getElementsByTagName(“MyBase64Element”)
MyInfo .Item(0).DataType = “bin.base64”

Dim image() As Byte
image = MyInfo .Item(0).nodeTypedValue

then you can use it in a byte array and convert to an image or whatever datatype you need.

The key here is overriding the type (probably Variant/String by default) to “bin.base64” and then making sure to use the “nodeTypedValue”

This one threw me for a loop for a little while 🙂

Technorati tags: , , , , , , ,

By Steve Novoselac

Director of Digital Technology @TrekBikes, Father, Musician, Cyclist, Homebrewer

3 replies on “VBA – Reading a Base64 Element into XML and using as Byte Array”


Great post, thanks very much.

Now the inevitable begging part:

Do you happen to have a solution for doing it the other way around?

ie I need to send image and other filetypes (eg PDF) as base64 encoding via XML to a MySQL 5 database.

As I don’t want to hold the images in Access (there are 5,000+!), I thought that as the DOMDocument was being created, when I reached an Image or File part of the export, I could go to the file on the filesystem, import the file as an object, and then add the Base64 encoding value to as an XML node, then destroy the object.

That’s my theory. I have no idea how to implement it though!

Any pointers would be welcome 🙂


Aha! I found teh answer myself:

I just need to use the following:

nodImage.DataType = “bin.base64”
nodImage.nodeTypedValue = rsTables!FileOLE.Value

where nodImage is an IXMLDOM Element and the FileOLE field is an OLE Object (just for testing purposes – I’ll load it from file in the final version)


My question is.. how could I convert the bytes array into image ? I haven’t found any resolution to this this even on the “dead’s page on Google” (page no. 2) 🙂 so this is very sad..
Hope you could help me. Thank’s!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.