我正在编码一个文档,作为base64编码元素附加到xml文档中以进行传输。这很简单,我只是将整个文件放入一个字节数组中,然后使用MSXML的nodeTypedValue对数据进行base64编码,因为我将它放入元素中。然而,问题是MS XML然后将自己的命名空间和数据类型属性添加到元素中,使得xml输出失败验证。我正在使用的代码低于输出。
如何禁止将“xmlns:dt =”urn:schemas-microsoft-com:datatypes“dt:dt =”bin.base64“”属性附加到元素?
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
输出:
<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>
答案 0 :(得分:1)
应该在当地人中挖掘一下:
xmlBinaryDocument.removeAttribute "dt:dt"