Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Embedded Image conversion 1

Status
Not open for further replies.

Malchik

Programmer
Dec 8, 2001
148
CA
Hi,

I am fairly new to the XML world. I will received XML files through a Web Service and there will be embedded images in the files. I was able to import the XML into Microsoft Access (no schema was provided, so the proper table and fields will be created) and then Import the tables in SQL 2000. The 'image' field is a NCHAR. How can I convert that to a Image data type? or using VB?

Thanks for any help you can provide.

Mal'chik [bigglasses]
 
Images in XML will be string encoded base64. To view the image, you'll need a base64 decoder

Jon

"I don't regret this, but I both rue and lament it.
 
Thanks a lot JohtyMC, that was very helpful!

Mal'chik [bigglasses]
 
Hi,
Here is what I did, just in case it can be helpful to other (this is VB6 code)

You need to add the reference: Microsoft XML, vx.x
Copy the code below and just call

Call XMLSaveBinaryFile(XMLDecodeBase64(sTmp), sFile)
Where sB64 hold the Base64 converted image and sFile the path and image name

Public Function XMLDecodeBase64(ByVal strData As String) As Byte()
Dim objXML As MSXML2.DOMDocument
Dim objNode As MSXML2.IXMLDOMElement

Set objXML = New MSXML2.DOMDocument
Set objNode = objXML.createElement("b64")
objNode.dataType = "bin.base64"
objNode.Text = strData
XMLDecodeBase64 = objNode.nodeTypedValue

Set objNode = Nothing
Set objXML = Nothing
End Function

Public Sub XMLSaveBinaryFile(ByRef vConvertedImage As Variant, ByVal sFileName As String)
Dim strmImage As ADODB.Stream
Dim options As ADODB.SaveOptionsEnum

Set strmImage = New ADODB.Stream
strmImage.Open
strmImage.Type = adTypeBinary
strmImage.Write vConvertedImage
strmImage.Flush
strmImage.SaveToFile sFileName, adSaveCreateNotExist
strmImage.Close

Set strmImage = Nothing
End Sub

Mal'chik [bigglasses]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top