Xml node encoding base64

Hi, i am stil trying to convert a vb6 project to xojo.
There is a couple of instructions that do not work:

objNode.DataType = "bin.base64" objNode.TypedValue = arrData

The code in vb6 is as follows:

[code]encodeBase64Cancelacion (ByRef arrData() As Byte)
Dim objXML As XmlDocument
Dim objNode As XmlElement
objXML = New XmlDocument
objNode = objXML.createElement(“b64”)

objNode.DataType = “bin.base64”
objNode.TypedValue = arrData

Return objNode.ToString[/code]

Any clue on how can i solve this in xojo?

That seems like a lot of code to encode a string to base64. Have a look at http://documentation.xojo.com/index.php/EncodeBase64.

In the VB application does this also put a specific attribute on that node ?

EncodeBase64 is supposed to recieve a string and i´ve got a binary array.
But in LR it also says “EncodeBase64 lets you encode arbitrary binary data into a 64-character alphabet composed of the printable ASCII characters.”
So, will it work? i`ll try…

is this the method that got the data from the byte array we converted last week ?
the reason I ask is that there are some things that in vb you would do very differently in xojo
like passing around an array of bytes instead of a memoryblock

and a memoryblock can be encoded in base 64 with 1 line of code

Yes the one last week is the first method i got, it calls the second one.
Well, here are both methods i got in vb6 to code into xojo:

Public Sub ObtenerCertificadoBase64() Dim fileNum As Integer Dim fileLength As Integer Dim bytes() As Byte Dim data As Byte Dim i As Long fileNum = FreeFile Open "C:\\TimbrarFactureHoyConPeticionSoap\\PKI\\archivo.pfx" For Binary As fileNum fileLength = LOF(fileNum) ReDim bytes(fileLength) i = 0 Do While Not EOF(fileNum) Get fileNum, , data bytes(i) = data i = i + 1 Loop Close fileNum PfxEnBase64 = encodeBase64(bytes) End Sub

[code]Private Function encodeBase64(ByRef arrData() As Byte) As String
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.nodeTypedValue = arrData
encodeBase64 = objNode.Text

Set objNode = Nothing
Set objXML = Nothing

End Function[/code]

Is there a simple way to do the encoding?

Something like these 4 lines :stuck_out_tongue:

Public Sub ObtenerCertificadoBase64()
  dim f as Folderitem = GetFolderItem("C:\\TimbrarFactureHoyConPeticionSoap\\PKI\\archivo.pfx", Folderitem.PathTypeNative)
  dim b as binaryStream = BinaryStream.Open( f )
  dim bytes as string = b.Read( b.length )
  PfxEnBase64 = encodeBase64(bytes)
End Sub

This is why I suggested not trying to “port” code but literally rewrite it in Xojo
If you try to port code you end up doing a lot of unnecessary gyrations

Long time developers in Xojo also suggest “rewrites” instead of “ports”

Yep. That’s why I questioned the use of a byte array in your previous post.

well pretty impresive.
at least i got no errors and the project does run.
I just have to check on the results.
thank you Norman and the rest of you guys!