binary data in XML

wxdqz

New Member
Hi,I've been struggling with storing binary data in an XML document.Below is some sample VB code that loads a bitmap into a string buffer, thencopies the string buffer to XML. Strangely, the XML element cuts off thestring buffer whereas the VB string data type manages to hold the entirebitmap.AFAIK, both the VB string datatype and XML store strings in unicode, so Icannot come up with a reason for the differences.I would greatly appreciate if someone could help me out with this.Here is the code (you will need a reference to the MSXML object):Private Sub Command1_Click()Dim doc As DOMDocumentDim testelement As IXMLDOMElementDim ImgBuff As StringDim nFile As IntegerConst conImagePath As String = "c:\winnt\gone fishing.bmp"'read bitmap into string buffernFile = FreeFileOpen conImagePath For Binary Access Read As #nFileImgBuff = Space(LOF(nFile))Get #nFile, , ImgBuffClose #nFile'test saving bitmap from string buffernFile = FreeFileOpen "c:\test.bmp" For Binary Access Write As #nFilePut #nFile, , ImgBuffClose #nFile'create xml documentSet doc = New DOMDocumentSet testelement = doc.createElement("image")testelement.Text = ImgBuffDebug.Print (testelement.Text = ImgBuff)doc.appendChild testelement'test saving bitmap from xml documentnFile = FreeFileOpen "c:\test2.bmp" For Binary Access Write As #nFilePut #nFile, , testelement.TextClose #nFileEnd Sub
 
Back
Top