I'm encoding a document to attach as a base64 encoded element inside an xml document for transmission. It's easy enough, I just slurp the entire file into a byte array and then use MSXML's nodeTypedValue to base64 encode the data as I put it into the element. The problem, however, is that MS XML then adds its own namespace and datatype attributes into the element, making the xml output fail validation. The code I'm using is below as well as the output.
How do I suppress the "xmlns:dt="urn:schemas-microsoft-com:datatypes" dt:dt="bin.base64"" attributes being appended to the element?
Private Function xmlBinaryDocument(filePath As String) As IXMLDOMElement
Dim xmlDOM As MSXML2.DOMDocument60
Set xmlDOM = New MSXML2.DOMDocument60
Set xmlBinaryDocument = xmlDOM.createNode(NODE_ELEMENT, "document", NS)
Dim strExtension As String
Dim strMimeType As String
Dim fso As FileSystemObject
Set fso = New FileSystemObject
' Info about file
strExtension = fso.GetExtensionName(filePath)
strMimeType = extToMime(strExtension)
' Now read the file as binary data into a byte array
Dim file() As Byte
file = GetFileBytes(filePath)
' Store it in the xml element as a base64 datatype
xmlBinaryDocument.dataType = "bin.base64"
xmlBinaryDocument.nodeTypedValue = file
' attributes
xmlBinaryDocument.setAttribute "document_content_type", strMimeType
xmlBinaryDocument.setAttribute "document_encoding_type", "base64"
xmlBinaryDocument.setAttribute "document_extension", strExtension
End Function
Output:
<document xmlns:dt="urn:schemas-microsoft-com:datatypes" dt:dt="bin.base64"
document_content_type="application/rtf" document_encoding_type="base64"
document_extension="rtf">***base64 encoded file here***</document>