VBA question: Putting ByteArray into an XML doc
-
Hi everone, I am using VBA for Visio and I want to store an image into an XML element. So, basically I read the image into a byte array like this: Dim FileNumber As Integer Dim imageBase64() as Byte FileNumber = FreeFile() Open "C:\hello.gif" For Binary As FileNumber ReDim imageBase64(LOF(FileNumber)) Get FileNumber, , imageBase64 Close FileNumber This reads the image data correctly into my byte array. But now wheever I attempt to put this into an XML element like: element.nodeTypedValue = imageBase64 This method does something to the image data and adds something else instead. What I want is to have the byte array as is. Any help would be greatly appreciated. Thanks! Pankaj /** I'm the one who's gonna have to die When it's time for me to die So let me live my life The way I want to - Jimi Hendrix */
-
Hi everone, I am using VBA for Visio and I want to store an image into an XML element. So, basically I read the image into a byte array like this: Dim FileNumber As Integer Dim imageBase64() as Byte FileNumber = FreeFile() Open "C:\hello.gif" For Binary As FileNumber ReDim imageBase64(LOF(FileNumber)) Get FileNumber, , imageBase64 Close FileNumber This reads the image data correctly into my byte array. But now wheever I attempt to put this into an XML element like: element.nodeTypedValue = imageBase64 This method does something to the image data and adds something else instead. What I want is to have the byte array as is. Any help would be greatly appreciated. Thanks! Pankaj /** I'm the one who's gonna have to die When it's time for me to die So let me live my life The way I want to - Jimi Hendrix */
That's because you haven't converted the image to an actual Base64 string. All you've done is read the binary data and attempted to write it to a text file. This, of course, writes all kinds of special characters to the file which are no legal in an XML document. You have to either find a VBA library to convert binary data into a Base64 string and back, or encapsulate the binary data in a !CDATA XML element. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome